Operating System - HP-UX
1838936 Members
3213 Online
110131 Solutions
New Discussion

shell script - removing a symbol at the end of each lines

 
Victor Wang
Occasional Contributor

shell script - removing a symbol at the end of each lines

HI,
I have a configuration file of the form shown below:

I would like to extract all fields from the configuration file, except the alphabet B, and any $ at the end of the lines, appearing after @ symbols of each line.

Therefore, the expected result would be:
host1 - DPG_SVLinux @AFS @SMP
host2 - DPG_SVLinux @AFS @BIG_MEM @CLASS_A
host3 - DPG_SVLinux @AFS
host4 - DPG_SVLinux @AFS

I have attempted to extract the fields by doing:
grep ^B config.*|cut -d ":" -f2 |sed s/^B// >outfile.txt

Note that I'm attempting to read a list of such configuration files in my direction having the same format as shown above (see attached file for full format of config file), and compiling all of such output into the file outfile.txt.

However, I'm not able to remove the $ string that appears after the @ symbols.

The current output looks as follows:
host1 - DPG_SVLinux @AFS @SMP $1
host2 - DPG_SVLinux @AFS @BIG_MEM @CLASS_A $1
host3 - DPG_SVLinux @AFS $2
host4 - DPG_SVLinux @AFS

Could anyone help me out by telling me how I should remove the $ symbol, if it appears at the end of each line?

Thanks
2 REPLIES 2
Chris Wilshaw
Honored Contributor

Re: shell script - removing a symbol at the end of each lines

The sed string to remove that is

sed -e s/"\$[0-9]$"//g

the \ escapes the $ sign, and [0-9] means any matching digit.

The 2nd $ sign indicates an end of line marker.
Michael Schulte zur Sur
Honored Contributor

Re: shell script - removing a symbol at the end of each lines

Hi,

try this.

Michael