Reputation: 2497
My input text is in this format
aa5b r1 12715
r2 12221
aa43b ew 13721
eb 122331
aa4b ff 1055440
Output must be
aa5 r1 12715
r2 12221
aa43 ew 13721
eb 122331
aa4 ff 1055440
I tried with
awk -F " " '{print $1}' t1 | grep "^aa*" > t2|sed s/b//g t2
The problem with this code is that the input text is not having a fixed pattern.
Upvotes: 3
Views: 1986
Reputation: 212208
The specifications are not clear from your description of the problem, but if you just want to delete all occurrences of the character 'b' on lines that begin 'aa', you can use:
sed '/^aa/s/b//g'
Upvotes: 1
Reputation: 63688
awk ' $1 ~ /a/ { $1= substr($1,0,length($1)-1) };1' infile > outfile
Upvotes: 0
Reputation: 22252
It'd be easier to use something like perl and regex:
perl -p -e 's/^(aa[0-9]+)\w+/$1/' t1 > t2
Upvotes: 1