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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk with « ^A » as separator (two caracters) 2

Status
Not open for further replies.

uzel

MIS
Oct 17, 2002
5
FR


Hello,
I have a text file with ^A as separator (136;101). I have line in a text file like the following example:
aax^Abbbx^AcAccx^Adddx^AAABB
aax^Abbbx^AcAccx^Adddx^AAABB

I expect to remove everything between the second ^A and the fourth ^A.
The result must be:
aax^Abbbx^AAABB
aax^Abbbx^AAABB

I am not able to use two characters as a separator. Do you have any idea?

I try: awk -v FS='\136' '{print $1"|"$2"|"$5}' file1 but it is only one separator.

Thanks in advance

 
What about this ?
Code:
nawk -F'[A^]+' '{print $1"|"$2"|"$5}' file1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
One way would be to pre-process your file, changing all ^A's to comma (,) using sed for instance then pipe that into an awk command. Something like (not tested)

sed 's/\^A/,/g' your_file | awk -v FS=',' '{print $1"|"$2"|"$5}'


In order to understand recursion, you must first understand recursion.
 
Thanks both for your answer.
PHV: I'm looking for "^A" not "A^"
Taupirho: Thanks, I just have to find a substitute character not in the text file yet and I'll be great.
Uzel,
 
I'm looking for "^A" not "A^"
did you even try my suggestion ?
 
Hi PHV,
Yes I tried,
bsp:/admin/temp> nawk -F'[A^]+' '{print $1"|"$2"|"$5}' file1
aax|bbbx|dddx
aax|bbbx|dddx
instead of
aax|bbbx|AABB
I'm not able to make it working proberly.
Uzel,

 
OOps, sorry.
You may use this:
Code:
awk '{split($0,a,/\^A/);print a[1]"|"a[2]"|"a[5]}' file1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for your help it work fine.
Uzel,
 
this also works :
Code:
awk -F'\\^A' '{print $1"|"$2"|"$5}'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top