I have an input file with content like :
18:51:18 | 217863|Acct 0110855565|RC 17608| 16 Subs| 1596 UsgRecs| 2 Secs| 430 CPUms| prmis2:26213 <MoveUsage d
aemon needs to run on this account before it can be billed.>
23:03:30 | 896529|Acct 2063947620|RC 17608| 8 Subs| 148 UsgRecs| 1 Secs| 280 CPUms| prbru6: 244 <MoveUsage d
aemon needs to run on this account before it can be billed.>
I need to extract acct nbr <in Bold letters> and need to put them in a new file liny by line..can any one please help me out in this :-/
Expecting your file is a plain text so try this...
awk -F\| '{for(i=0;++i<=NF;) if($i ~ /Acct/) print $i}' infile
1 Like
Simple grep solution
grep -o 'Acct [0-9]*' inputfile
# Or through Sed
sed -n 's/.*Acct \([0-9][0-9]*\).*/\1/p' inputfile
1 Like
I tried the one you have given...Thanks for the help..Its almost worked..
But I need a small correction..
Am getting the output as :
Acct 0110855565
Acct 2063947620
Can you make correction to the above solution to get the output as :
0110855565
2063947620
awk -F'[| ]*' '{print $4}' infile
cut -c24-33 infile
I tried the one you have given...Thanks for the help..Its almost worked..
But I need a small correction..
Am getting the output as :
Acct 0110855565
Acct 2063947620
Can you make correction to the above solution to get the output as :
0110855565
2063947620
---------- Post updated at 07:40 AM ---------- Previous update was at 07:39 AM ----------
I tried the one you have given...Thanks for the help..Its almost worked..
But I need a small correction..
Am getting the output as :
Acct 0110855565
Acct 2063947620
Can you make correction to the above solution to get the output as :
0110855565
2063947620
Did you try Sed or other awk solutions..?
grep -oE '[0-9]{9,}' inputfile # assuming minimum of 9 digits for Acc numbers
1 Like
Yes I tried but It didnt work..It is saying as illegal option -o n -E ..
I tried the one you have given...Thanks for the help..Its almost worked..
But I need a small correction..
Am getting the output as :
Acct 0110855565
Acct 2063947620
Can you make correction to the above solution to get the output as :
0110855565
2063947620
-------- Post updated at 07:40 AM ---------- Previous update was at 07:39 AM ----------
I tried the one you have given...Thanks for the help..Its almost worked..
But I need a small correction..
Am getting the output as :
Acct 0110855565
Acct 2063947620
Can you make correction to the above solution to get the output as :
0110855565
2063947620
awk -F\| '{for(i=0;++i<=NF;) if($i ~ /Acct/) print substr($i,6)}' infile
--
1 Like
It didnt work with grep but worked with sed...Thanks for the sol'n..
---------- Post updated at 08:01 AM ---------- Previous update was at 07:58 AM ----------
It worked fine...ThankYou