want to print the file content from the specific line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting want to print the file content from the specific line
# 1  
Old 02-21-2012
want to print the file content from the specific line

Hi All,

I would like to print the content from the specific line of a file .

For example... i have file abc.txt which has 100 lines of code ,from this file i would like to print the content from 20,19,18th line......like that


Regards
Srikanth
# 2  
Old 02-21-2012
Use the below awk command
Code:
awk 'NR==20 NR==19 NR==18' "abc.txt"


Last edited by Franklin52; 02-21-2012 at 03:18 AM.. Reason: Please use code tags for code and data samples, thank you
# 3  
Old 02-21-2012
thanks for the reply.. Could you please specify any command to print from 20thline to 1st line instead of giving all the line numbers like above..?
# 4  
Old 02-21-2012
Code:
sed -n '1,20p;20q' abc.txt | tac

# 5  
Old 02-21-2012
You can also modify the above awk and use.
Code:
awk 'NR==1, NR==20' "abc.txt"

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 02-21-2012 at 03:20 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break a line content and print as column

Hi, I have urls in my input file like this (1 Reply)
Discussion started by: tmonk1
1 Replies

2. Shell Programming and Scripting

awk to print specific line in file based on criteria

In the file below I am trying to extract a specific instance of path, if the adjacent plugin": "/rundb/api/v1/plugin/49/. Thank you :). file "path": "/results/analysis/output/Home/Auto_user_S5-00580-4-Medexome_65_028/plugin_out/FileExporter_out.52", "plugin": "/rundb/api/v1/plugin/49/",... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Help to print the line that share exactly same with column one content

Input file : AAAG TC AACCCT AACCCT AACCCT AACCCT TCTG TCTG TCTG AC AC TCTG TCTG AC AC AC AC AC AGTG AC AGTG TCC Desired output file : AACCCT AACCCT AACCCT AACCCT AC AC I would like to print out the line that share exactly same as the first column data content. Column one data... (4 Replies)
Discussion started by: perl_beginner
4 Replies

4. Shell Programming and Scripting

Print specific line using a variable

Hi Everyone, Is there a way I can print specific lines using sed -n '3,3p' file.dat or awk 'FNR==3' file.dat when using variable? For example, I have this script (get_line.ksh) that accepts line parameter that a user wanted to print in the file.dat. file.dat one two three four ... (1 Reply)
Discussion started by: zzavilz
1 Replies

5. Shell Programming and Scripting

Print String Every Specific Line

Dear All, I have input file like this, 001 059 079 996 758 079 069 059 079 ... ... Desired output: AA 001 BB 059 (4 Replies)
Discussion started by: attila
4 Replies

6. Shell Programming and Scripting

Help to just print out specific line from an input file

Hi, I have a file which contains 2,500,500,432 lines. Can I know what command I should type in order just print out particular line from the input file? eg. I just wanna to see what is the contents at line 522,484,612. Thanks for advice. (3 Replies)
Discussion started by: perl_beginner
3 Replies

7. Shell Programming and Scripting

Break a line content and print as column

Hi, I have urls in my input file like this http://unix.com/abc/def http://unix.com/kil/min I want to use the / as separator and print the last content as another column like this http://unix.com/abc/def def http://unix.com/kil/min min I was using awk -F option and then joining the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

8. Shell Programming and Scripting

Passing parameter in sed or awk commands to print for the specific line in a file

Hi, I am trying to print a specific line in a file through sed or awk. The line number will be passed as a parameter from the previous step. My code looks as below. TEMP3=`sed -n '$TEMP2p' $FILEPATH/Log.txt` $TEMP2, I am getting from the previous step which is a numerical value(eg:3). ... (2 Replies)
Discussion started by: satyasrin82
2 Replies

9. Shell Programming and Scripting

Edit file content at the specific line.

How to edit file content at the specific line? For example at below The things to edit --> This is line 2. And it is below line 1. This is line 1. This is line 2. # i want to append some words at this row line. How? This is line 3. (8 Replies)
Discussion started by: alvin0618
8 Replies

10. Shell Programming and Scripting

Perl Script - Print Content of next line

Good evening to you all perl experts I need your help I have a very simple script where I´m trying to print a line from status.dat file. The script will find the line containing "servicestatus", and I want to print the content of the next line. For example, the file contains this text:... (6 Replies)
Discussion started by: zarahel
6 Replies
Login or Register to Ask a Question