Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing "*" and ";" using awk 1

Status
Not open for further replies.

vodkadrinker

Technical User
May 16, 2002
163
GB
I have a file which has a similar structure to the following test.file

AAAAA1*******
AA2;;;;;;;;;;;;
BBBB1*******
BBBBBBBBBB2;;;;;;;;

I have used the following script to list 1 line per record so in this case each record has 2 fields.

for i in `pr -2 -t -a -s" " /test.file|awk '{print $1","$2}'`
do
echo $i
done

and the result is...

AAAAA1*******,AA2;;;;;;;;;;;;
BBBB1*******,BBBBBBBBBB2;;;;;;;;

Is there a better way to do this and how can I trim all the "*" and the ";" from the output.
 
sed can take off the characters easily with

for i in `pr -2 -t -a -s" " /test.file|awk '{print $1","$2}' | sed 's/[\*;]*//g'`
do
echo $i
done

or sed could everything such as

for i in `pr -2 -t -a -s" " /test.file|sed 's/^I/,/;s/[\*;]*//g'`
do
echo $i
done

where the ^I is a tab character which you can type as a tab or as ctrl-V ctrl-I.
Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Yes, you can do it easy with sed

sed 's/[;,*]//g' test.txt > test2.txt

the command will remove every ; and * from file 'test.txt' and print it to 'test2.txt'


Or just
sed 's/[;,*]//g' test.txt

if you want to se the output.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top