Display 3rd line of a file using cut only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display 3rd line of a file using cut only
# 8  
Old 12-20-2010
none of the options are giving desired result
# 9  
Old 12-20-2010
Quote:
Originally Posted by Deepak Dutt
none of the options are giving desired result
My Post#7 should work. In that I m just merging all lines by |(pipe) delimiter and than printing 3rd column.
Code:
$ cat input
line1
line2
line3
line4
line5
$ xargs -d"|" < input
line1|line2|line3|line4|line5
$ xargs -d"|" < input | cut -d"|" -f3
line3

To get further idea on your problem, please post sample input data and desired output data.
R0H0N
# 10  
Old 12-20-2010
This does the job:
Code:
sed -n 3p inputfile

Is there another reason you want to stick with cut?




Robin,
Liverpool/Blackburn
UK
# 11  
Old 12-20-2010
Quote:
I tried this command in all three shells TCSH BASH and KSH
As I am sure you know already, this whole exercise with "cut" is a complete waste of time.
# 12  
Old 12-20-2010
Code:
$ cat input
line1
line2
line3
line4
line5
 
$ cut -d'
' -f 3 input
line3

# 13  
Old 12-21-2010
Exactly, Ygor's suggestion seems to be working well.

bash/ksh93:
Code:
$ cut -d$'\n' -f3 infile
this is 3rd line

Perhaps there is something fishy with the OP's input file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

2. Shell Programming and Scripting

cut the variable from the line and use it to find the file and read the content of that file

Hi, I am working on one script..I am having files in the below format file 1 (each line is separated with : delimeter) SPLASH:SPLASH:SVN CIB/MCH:MCH:SVN Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

3. Shell Programming and Scripting

cut certain characters for each line in a file

Hi Everyone, i have a file 1.txt <a><a"" dd>aaaaauweopriuew</f><">!(^)!</aa></ff> <a><a"" dd>bbbbbuweopriuew</f><">!(^*)!</aa></ff> i know i can use perl -p -i -e "s/>aaaaa/aa/g" 1.txt perl -p -i -e "s/>bbbbb/bb/g" 1.txt to acheive only keep the first two characters of the five characters,... (4 Replies)
Discussion started by: jimmy_y
4 Replies

4. Shell Programming and Scripting

How do I create an array from a file using every 3rd line

A file contains the following information shown below. Every ceName has 2 consecutive lines that have to be evaluated, using awk, sed, cut (any common unix tools). Input file: ceName: Node-1 processName: tzMgmt Status: PROCESS_NOT_RUNNING ceName: Node-2 processName: tzMgmt Status:... (15 Replies)
Discussion started by: BRH
15 Replies

5. Shell Programming and Scripting

How can i cut first line of a file

i want to cut first line of a file and use it.It should remove that line from file content.Plz help me (7 Replies)
Discussion started by: arghya_owen
7 Replies

6. Shell Programming and Scripting

how to cut first 3 characters of each line in a file

Hi Friends I have a file like sample1.txt ------------ 10998909.txt 10898990.txt 1898772222.txt 8980000000000.txt I need to take first 3 characters of each line in a file and i need to print it ' like loop 109 108 189 898 (7 Replies)
Discussion started by: kittusri9
7 Replies

7. Shell Programming and Scripting

how to grep a file and cut a corresponding value from the line

i have to grep a file which has contents like /Source/value/valuefile/readme.txt DefaultVersion:=1.7 I have to grep this file with "/Source/value/valuefile/readme.txt" and cut the corresponding value "1.7" from the same line i tried grep and cut but not working. (1 Reply)
Discussion started by: codeman007
1 Replies

8. Shell Programming and Scripting

How to extract 3rd line 4th column of a file

Hi, Shell script: I would need help on How to extract 3rd line 4th column of a file with single liner Thanks in advance. (4 Replies)
Discussion started by: krishnamurthig
4 Replies

9. Shell Programming and Scripting

Print starting 3rd line until end of the file.

Hi, I want to Print starting 3rd line until end of the file. Pls let me know the command. Thanks in advance. (1 Reply)
Discussion started by: smc3
1 Replies

10. Shell Programming and Scripting

How to print 3rd to last line of file?

Hi, I have a ksh script I would like to modify. What I need it to do is look at an ever changing log file and print the 3rd to last line. Is there a command that will display this? I can not use line numbers because the file is always growing. Thanks for any help (2 Replies)
Discussion started by: NivekRaz
2 Replies
Login or Register to Ask a Question