Hi,
I have file from which i need to copy the data except the last coloum. The content of the file is as below.
SUB_KEY|Acxiom_WLS_SMS_Key|MDN|MKT_CD|SITE_CD|BILL_ACCT_ID|BILL_SYSTEM_CD|FIRST_NAME|LAST_NAME|OfferVersion|CellCode|Drop_Sequence_Number1|TrackingCode
10000911|WLS+10640771+10000911|2X8812073|V2|790|3590247130|V2|KATIE|ANDERSON|000002019_V511|A424|1|000027083
i want to remove the coloum tracking code and its value.
Regards
Sid
cut -d\| -f -12 infile
---------- Post updated at 04:16 PM ---------- Previous update was at 04:15 PM ----------
Sorry...just noticed the title - does it have to be in awk ?
Not realy, as long as i get the data correct thats ok.
Well, if your interested anyway...
awk -F\| '{ for(i=1;i < NF;i++) { if(i > 1) printf("|"); printf("%s",$i); } print ""; }' infile
kshji
5
awk -F '|' 'BEGIN { OFS="|" }
{ $NF="" ; print }
' infile
And if like remove last |
then
awk -F '|' 'BEGIN { OFS="|" }
{ $NF="" ; print }
' infile | sed 's/|$//'
using shell
cat infile | while read line
do
echo "${line%|*}"
done
Awk (and sed for that matter) never cease to amaze me...
I always write too much of a "program" when I do mine...
Couple of small issues - dont know if they're a problem.
Field separator of pipe goes missing, and there is an extra separator on the end...
---------- Post updated at 05:26 PM ---------- Previous update was at 05:25 PM ----------
sorted:
awk -F '|' '{ OFS="|"; NF-- ; print }'
sed 's/\(.*\)|[^|]*/\1/' file
cabrao
8
awk -F\| NF-=1 OFS=\| file
you need to re-eval the record AFTER 'NF-=1'...
nawk -F'|' 'NF--&&$1=$1' OFS='|' myFile