Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
delete line from the file if there is no thir
Name: neeleshmrt Date: May 22, 2009 at 04:04:47 Pacific OS: LInux Subcategory: Theory
Comment:
Please help me writing a spinet which can delete the line from a file which does not have thrird field
the file contains some like ,,, xxx yyy zzz cccc yyyy xxx yyy xxx yyy nnn nnn nnn xxx yyy nnn nnn nnn
Name: ghostdog Date: May 22, 2009 at 04:18:00 Pacific
Reply:
if you have Python
#!/usr/bin/env python
for line in open("file"):
if len(line.split())>=3:
print line.strip()
if you prefer awk
awk 'NF>=3' file
0
Response Number 2
Name: neeleshmrt Date: May 22, 2009 at 04:42:34 Pacific
Reply:
Thanks for the fast response,but that 's not what i want to do.Because of unfamiliarity i would not prefer to use python..rather prefer using awk / sed
Problem here is i have a file having thousands of lines and i want to delete all the lines that do not have third field.
0
Response Number 3
Name: ghostdog Date: May 22, 2009 at 05:06:41 Pacific
Reply:
so try the awk one liner and see if its what you want. Being unfamiliar is not an excuse not to try out new things.
0
Response Number 4
Name: neeleshmrt Date: May 22, 2009 at 05:13:17 Pacific
Reply:
Thanks for you suggestion !
0
Response Number 5
Name: neeleshmrt Date: May 22, 2009 at 05:52:36 Pacific
Reply:
I have the answer now ....
cat newio|\ while read LINE do echo $LINE x=`echo $LINE | cut -d" " -f3` y=${#x} if [ $y -eq 0 ] then echo "do nthing" else echo $LINE >> temp1 fi done
Name: ghostdog Date: May 22, 2009 at 06:54:40 Pacific
Reply:
if you want to use some bash scripting instead of that awk one liner, then there is no need to use cat, which is useless in this case, and there is no need to use cut to get the 3rd field
while read a b c
do
if [ ! -z "$c" ];then
printf "$a $b $c\n"
fi
done < file
for big files, try not to use bash's while read loop. its slower than using awk
0
Response Number 8
Name: FishMonger Date: May 22, 2009 at 07:14:14 Pacific
Summary: Hi I have to import a file.txt with real E notated (like 2.3E-12) numbers in 2 columns in it (coordinates basicly - x and y) in to C or C++ Do you actually have to read all of the numbers into your pr...
Summary: Hi Friend, In batch code, is it possible to read a particular line from the text file. For eg., Text file "test1.txt" contains the following text.... data1 data2 data3 data4 data5 I need to read th...
Summary: Hey! i have a txt file that contain a large numb of database! i need to delete the column that have a date less than 2006! can i create a batch file, that do this work! ...