trying to print selected fields of selected lines by AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trying to print selected fields of selected lines by AWK
# 1  
Old 05-05-2010
Question trying to print selected fields of selected lines by AWK

I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by
awk 'NR==29,NR==10029' File1 > File2

and then doing

awk '{print $1, $2, $13, $14}' File2 > File3

Can somebody tell me how to combine this in one code?Smilie
# 2  
Old 05-05-2010
Quote:
Originally Posted by ananyob
I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by
awk 'NR==29,NR==10029' File1 > File2

and then doing

awk '{print $1, $2, $13, $14}' File2 > File3

Can somebody tell me how to combine this in one code?Smilie
Code:
awk 'NR>=29  && NR<=10029 {print $1, $2, $13, $14}' File1 > File2

# 3  
Old 05-05-2010
thanks Franklin......the code worked....i wish i knew it was so easy to combine both with the && in between.....thanks a lot Smilie
# 4  
Old 05-05-2010
Quote:
Originally Posted by ananyob
thanks Franklin......the code worked....i wish i knew it was so easy to combine both with the && in between.....thanks a lot Smilie
The expressions you were using originally would work as well:
Code:
awk 'NR==29,NR==10029 {print $1, $2, $13, $14}' File1 > File2

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find key pattern and print selected lines for each record

Hi, I need help on a complicated file that I am working on. I wanted to extract important info from a very huge file. It is space delimited file. I have hundred thousands of records in this file. An example content of the inputfile as below:- ## ID Ser402 Old; 23... (2 Replies)
Discussion started by: redse171
2 Replies

2. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

3. Shell Programming and Scripting

How to print selected fields

HI, I am using below command to display the words, but i am getting awk error. Please help me out on this I am using below code i am getting error as If i use below code i am getting below OP Output from where i am trying to select the fields after delimiter "," from here i want to... (5 Replies)
Discussion started by: darling
5 Replies

4. Shell Programming and Scripting

AWK script - extracting min and max values from selected lines

Hi guys! I'm new to scripting and I need to write a script in awk. Here is example of file on which I'm working ATOM 4688 HG1 PRO A 322 18.080 59.680 137.020 1.00 0.00 ATOM 4689 HG2 PRO A 322 18.850 61.220 137.010 1.00 0.00 ATOM 4690 CD ... (18 Replies)
Discussion started by: grincz
18 Replies

5. Shell Programming and Scripting

Print selected lines from file in order

I need to extract selected lines from a log file, I can use grep to pull one line matching 'x' or matching 'y', how can I run through the log printing both matching lines in order top to bottom. i.e line 1 xyz - not needed line 2 User01 - needed line 3 123 - not needed line 4 Info - needed... (2 Replies)
Discussion started by: rosslm
2 Replies

6. Shell Programming and Scripting

Sum value from selected lines script (awk,perl)

Hello. I face this (2 side) problem. Some lines with this structure. ........... 12345678 4 12345989 13 12346356 205 12346644 74 12346819 22 ......... The first field (timestamp) is growing (or at least equal). 1)Sum the second fields if the first_field/500 are... (8 Replies)
Discussion started by: paolfili
8 Replies

7. Shell Programming and Scripting

shell script(Preferably awk or sed) to print selected number of columns from each row

Hi Experts, The question may look very silly by seeing the title, but please have a look at it clearly. I have a text file where the first 5 columns in each row were supposed to be attributes of a sample(like sample name, number, status etc) and the next 25 columns are parameters on which... (3 Replies)
Discussion started by: ks_reddy
3 Replies

8. UNIX for Dummies Questions & Answers

How to print selected pages

I have a large file and want to print out, but I don't want to print all, just some pages. Like if the file has 100 pages, I just want to print out page 3-34 and 67-87. How can I do? By the way, I already try "lp -o page-ranges=value" command which doesn't work on my computer because -o <option>... (2 Replies)
Discussion started by: wendyz
2 Replies

9. Shell Programming and Scripting

print selected lines

Hi everybody: I try to print in new file selected lines from another file wich depends on the first column. I have done a script like this: lines=( "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "21" "31" "41" "51" "55" "57" "58" ) ${lines} for lines in ${lines} do awk -v ... (6 Replies)
Discussion started by: tonet
6 Replies

10. Shell Programming and Scripting

print selected rows with awk

Hi everybody: Could anybody tell me how I can print from a file a selected rows with awk. In my case I only want print in another file all the rows from NR=8 to NR=2459 and the increment each 8 times. I tried to this: awk '{for (i=8; i=2459; i+=8); NR==i}' file1 > file2 But doesn't... (6 Replies)
Discussion started by: tonet
6 Replies
Login or Register to Ask a Question