Recently I have to manipulate a huge text file (myfile.text), with 2000 columns. I only wanted to delete one column with the title "user1_comments", but I didn't know which column number was to use some command like cut.
awk 'END { if (!f++) print "pattern not found" }/^firstWordInTheLine/{ for(i=1;i<=NF;i++){if ($i ~ "user1_comments"){print "[line="NR,"column="i-1"]", f++} }}' myfile.text
The output was [line=3 column=1209] 0
So, I found the column number (1209) which "user1_comments" has. For deleting I used nawk.
nawk '{for(i=1;i<=NF;i++) line=(i==1)?$i:((i==1209)?line:line OFS $i);print line}' myfile.text -> newfile.text
Did you tried with cut? How did you make it? :)
Cheers!
No comments:
Post a Comment