Find and add a field for an input file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find and add a field for an input file
# 8  
Old 07-25-2012
Quote:
Originally Posted by V1l1h1
since my file has about 100000 records, would it be safe to write to a different output file instead of printing to screen? if so, please tell me how I can do that?
The same way you make any other shell command print to file instead of terminal. command > filename


Quote:
if you have time, please help me understand below two questions..

Two questions..
1) when I used AWK to print first column


perseus.gasleak(/usr/GLS/AMI/Pepco/Portable)% awk '{print $1}' phi_pep.txt

output is:
0000684631,E,3088017,7

perseus.gasleak(/usr/GLS/AMI/Pepco/Portable)% awk '{print $2}' phi_pep.txt

Why it is displaying like this?
You haven't told awk to use anything else, so it's assuming columns are separated by spaces. If you want it to use commas, give it -F","

Quote:
2) if "-F" is used for comma delimited record file, why didn't is print just the first column?
I'm not sure of your question here, but my best guess is that it split on the first whitespace it found.
# 9  
Old 07-25-2012
Mead, Thank you.. I have a little bit more understanding now..
Although, Scott didn't use "," in his syntax..


I still need to use Scott's format..
nawk -F, '{$8=substr($8,1+index($8,"_")) OFS $8}1' OFS=, phi_pep.txt > phiPep.txt ?
# 10  
Old 07-25-2012
What difference does it make to the program being run whether a comma is in quotes?
Code:
$ echo ,

,

$ echo ","

,

$

echo doesn't see the quotes. Neither does awk.
Quote:
nawk -F, '{$8=substr($8,1+index($8,"_")) OFS $8}1' OFS=, phi_pep.txt > phiPep.txt ?
Sure, as long as the file you're writing and the file you're reading aren't the same.
# 11  
Old 07-27-2012
Thank you for your quick response UNIX guru.. I got the ball rolling my side with your help..

Also appriciate your help folks, now, i know some UNIX ..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find pattern in first field of file

Hello all I have two files. 1. Pattern.txt - It contains patterns to be matched. It has large number of patterns to be matched. Cat Pattern.txt Ram Shyam Mohan Jhon I have another file which has actual data and records are delimted by single or multiple spaces. 2.... (8 Replies)
Discussion started by: krsnadasa
8 Replies

2. Shell Programming and Scripting

Find the position of a field/column in a flat file

Hi, Let say I have a file which has around 400 fields. SampleFile ========= PATIENTID|FACILITY|................|TIME_LAST_VISITED_BY_MD|.....|STATUS| How is it possible to find out which field is TIME_LAST_VISITED_BY_MD?fro example by seeing the above structure we can saw FACILITY... (5 Replies)
Discussion started by: machomaddy
5 Replies

3. Shell Programming and Scripting

find and replace in a directory using an input file

Hi folks, I need help to finish this script please. see below: I have an input file with all the IP address to names formated like so in a txt file addnsr1pri 166.7.3.105 addnsr1sec 166.2.100.22 addnsr2pri 166.2.220.121 addnsr2sec 166.3.68.45... (12 Replies)
Discussion started by: richsark
12 Replies

4. Shell Programming and Scripting

Find a word in input file

Hi, I had a input file containing, abcdefghij;20100903040607;1234567891;GLOBAL; abc123;20100903040607;12345;09;thestdf; def456;20100903040607;67891;04;bnkim; I need to search word GLOBAL in my file. If it is found then do something else do other thing How can i write if loop for... (13 Replies)
Discussion started by: Poonamol
13 Replies

5. Shell Programming and Scripting

How to check field formatting of input file?

Hi, I had input file with below data, abcdefghij;20100903040607;1234567891;GLOBAL; Having values of fields with seperated by semi-colon (;) and ended with line feed (\n). Through shell script, how can I check the field formatting? Thanks in advance. (18 Replies)
Discussion started by: Poonamol
18 Replies

6. UNIX for Dummies Questions & Answers

find uniq lines in file, using the first field of line

Hello all, new to unix and have just found the forum. I think I will be here quite often, and hope that in time i will be able to provide soem help, role on not being a newbie anymore :) I have a question which iI am hoping someone could help me with. If i have a file with lines in in thus... (8 Replies)
Discussion started by: grom
8 Replies

7. Shell Programming and Scripting

Find top N values for field X based on field Y's value

I want to find the top N entries for a certain field based on the values of another field. For example if N=3, we want the 3 best values for each entry: Entry1 ||| 100 Entry1 ||| 95 Entry1 ||| 30 Entry1 ||| 80 Entry1 ||| 50 Entry2 ||| 40 Entry2 ||| 20 Entry2 ||| 10 Entry2 ||| 50... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

8. Shell Programming and Scripting

Find lines in text file with certain data in first field

Hi all, Sorry for the title, I was unsure how to word my issue. I'll get right to the issue. In my text file, I need to find all lines with the same data in the first field. Then I need to create a file with the matching lines merged into one. So my original file will look something like... (4 Replies)
Discussion started by: rstev39147
4 Replies

9. Shell Programming and Scripting

How To Find Length of a Field in XML File

Hi I have a xml file with below data...have to find the length of the filedvalues... <?xml version="1.0" encoding="ISO-8859-15" standalone="no"?><abc xmlns:xsi="http://www.w3.org/2000/XMLSchem... (3 Replies)
Discussion started by: naughty21
3 Replies

10. Shell Programming and Scripting

Find script with input pattern file

Howdy: I have a file with 140+ file name patterns. Each prefix can have dozens of files with different extension names. e.g. 1-S51 1113-G6V 1117-G6V 1119-G6V 1127-G6V 12XW-AF5W 14-UA8N I need to search in 12 directories, (/data/lgc1/basin_mas to /data/lgc12/basin_mas) for all the... (8 Replies)
Discussion started by: iguanathompson
8 Replies
Login or Register to Ask a Question