| | |
Adding a new column in a text file
![]() |
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi,
I would like to add a new column in a text file which contains values based on the value of another column.
Eg:
suppose the text file contains:
1 abc 67
2 def 40
3 uty 57
.......
....
Now i would like to add a new column which contains value 'yes' if the column 3 > 40 else 'no'.
Is it possible using awk ??
I would like to add a new column in a text file which contains values based on the value of another column.
Eg:
suppose the text file contains:
1 abc 67
2 def 40
3 uty 57
.......
....
Now i would like to add a new column which contains value 'yes' if the column 3 > 40 else 'no'.
Is it possible using awk ??
•
•
Join Date: Oct 2008
Posts: 95
Reputation:
Solved Threads: 5
Shell Scripting Syntax (Toggle Plain Text)
$ awk '{ if ($3 > 40) four="yes"; else four="no"; print $0, four }' file 1 abc 67 yes 2 def 40 no 3 uty 57 yes $
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
Shell Scripting Syntax (Toggle Plain Text)
awk '{printf "%s %s",$0, ($3 > 40)? "yes" :"no"}' file
![]() |
Similar Threads
- insert csv file into mysql through php (PHP)
- reading, modifying data within .csv file (C++)
- Adding a new row in a Datagrid ??????????? (C#)
- Incompatible Types? (Java)
- Help regarding images in datagridview (C#)
- Open In New Window Php (PHP)
- extract columns from a text file in vb (Visual Basic 4 / 5 / 6)
- Jsp and XML (JSP)
- Import text into ListView? (C#)
Other Threads in the Shell Scripting Forum
- Previous Thread: using grep, sed, awk to pull links out of an XML file
- Next Thread: More Graphical screens
| Thread Tools | Search this Thread |





