logo
down
shadow

shell command to remove characters after a special character in bash/shell


shell command to remove characters after a special character in bash/shell

By : Savagearts
Date : November 19 2020, 12:41 AM
it helps some times I have filename , In bash, this is easy:
code :
$ f=hello_1.0_25.tgz
$ echo "${f%_*}"
hello_1.0


Share : facebook icon twitter icon
How to read from block special and character special devices in Linux using bash shell scripts?

How to read from block special and character special devices in Linux using bash shell scripts?


By : user3002505
Date : March 29 2020, 07:55 AM
Hope that helps Use dd to get blocks of data from the device. E.g. to get 8 bytes from /dev/urandom:
code :
dd if=/dev/urandom count=1 bs=8 | ...
$ dd if=/dev/urandom count=1 bs=8 2>/dev/null | od -t x1 -A n
b4 bc 2f 59 dd 55 1b 4a
$ echo $RANDOM $RANDOM $RANDOM $RANDOM
3466 6521 4426 9349
shell/bash: use sed/awk to get string between special characters

shell/bash: use sed/awk to get string between special characters


By : NathanM
Date : March 29 2020, 07:55 AM
To fix this issue suppose I have a string as , You can use awk:
code :
str='Al99.NegFRho.ZeroRhoR.ZeroPhiR.eam.alloy'
awk -F. -v OFS='\n' '{print $2, $3, $4}' <<< "$str"

NegFRho
ZeroRhoR
ZeroPhiR
awk -v RS=. 'NR>=2 && NR<=4' <<< "$str"

NegFRho
ZeroRhoR
ZeroPhiR
How to handle quotes, backtick special characters for running linux bash shell command in remote server

How to handle quotes, backtick special characters for running linux bash shell command in remote server


By : user2859468
Date : March 29 2020, 07:55 AM
To fix this issue Context: It seems this question originated as an XY Problem. OP appears to want to remove the 3 lines including and after the string "TA-aws-hf-{{client_code}}-{{env_name}}".
Backticks are deprecated; use $(modern $(command) substitution) when necessary. It is not necessary in this case.
code :
ssh splunk@10.145.32.172 'sed -i "/TA-aws-hf-{{client_code}}-{{env_name}}/,+2d" /opt/splunk/etc/system/local/serverclass.conf' 
ssh splunk@10.145.32.172 '
  cd /opt/splunk/etc/system/local
  awk "/TA-aws-hf-{{client_code}}-{{/ {i=-3} i++>0" \
    serverclass.conf > temp && mv $_ serverclass.conf
'
replace all special characters with a backslash plus special character in Unix Shell

replace all special characters with a backslash plus special character in Unix Shell


By : gael
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I need to replace the special character which is not alphanumeric with a backslash in a string. , Would you please try:
code :
echo "$orig_str" | sed 's/\([^[:alnum:]]\)/\\\1/g'
echo "$orig_str" | sed 's/[^[:alnum:]]/\\&/g'
find a special character in file & remove the special character, before/after words of special character using shell

find a special character in file & remove the special character, before/after words of special character using shell


By : Kuang Yuan Lin
Date : March 29 2020, 07:55 AM
hope this fix your issue A file contains email addresses. Requirement is to remove words present before/after a special character & also the special character from a file. , I'd use perl or sed
Related Posts Related Posts :
  • How do I use sed on a string?
  • Using bash variables for range in sed
  • convert a DURATION HH:MM:SS to seconds in bash
  • Shell make system paths click-able when printed out by my shell script
  • I want to use parallel-ssh to run a bash script on multiple servers, but it simple prints the echo statements
  • AWK between 2 patterns - first occurence
  • Nginx on docker - daemonize and attach to bash
  • Delete or Replace nth line in a file after a pattern match using shell scripts
  • Actual return code for SCP
  • How to exit a bash function that expects a return
  • Bash script to split file into two files while changing output file during processing
  • Pass command line arguments via sbatch
  • variable substitution (what do you call/name this method)?
  • Call function from another shell script
  • How to Grep and Replace With Exclusions
  • How do I run a script for 1st working day of every month in cron?
  • Bash Unexpected End of File Error After Installing RVM
  • Nested Loop with increment on inner loop?
  • video orientation detection in bash
  • Interrupt sleep in bash with a signal trap
  • Want file rename script to add number at end with fixed length
  • What's the DRYest way to replace a file with a symlink in bash
  • How to run Bitcoin's autogen.sh file?
  • Renaming files in folder and subfolders using a list- Bash Script/Unix
  • Bash command to compare more than two files
  • If It is a directory append text
  • What's wrong with my WHILE-DO loop, or why my script can't find the file I'm giving it on a plate?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org