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
# 1  
Old 12-17-2010
Display 3rd line of a file using cut only

Hello,
i want to use new line character in cut command

i want to display 3rd line of a file using cut only( not by sed or head -tail command)

can anyone suggest me ?

Regards
# 2  
Old 12-17-2010
Try...
Code:
cut -d '
' -f 3 file1

# 3  
Old 12-17-2010
I am not sure but I think this should also work.
Code:
cut -d"\r" -f3 file

R0H0N
# 4  
Old 12-17-2010
Hello,

I tried this command in all three shells TCSH BASH and KSH

it doesnot work
Code:
cat file
this is 1st line
this is 2nd
this is 3rd line
this is 4th line
%ingrx025:/home/grvobad2/shell/tes/deepak/shell >echo $SHELL
/bin/tcsh
%ingrx025:/home/grvobad2/shell/tes/deepak/shell >cut -d"\r" -f3 file
cut: invalid delimiter
%ingrx025:/home/grvobad2/shell/tes/deepak/shell >cut -d "\r" -f3 file
cut: invalid delimiter
%ingrx025:/home/grvobad2/shell/tes/deepak/shell >bash
bash-3.00$ cut -d"\r" -f3 file
cut: invalid delimiter
bash-3.00$ ksh
$ cut -d"\r" -f3 file
cut: invalid delimiter

---------- Post updated at 01:47 AM ---------- Previous update was at 01:43 AM ----------

Even i tried this
Code:
cut -d '\
? ' -f 3 file
this is 1st line
this is 2nd
this is 3rd line
this is 4th line
%ingrx025:/home/grvobad2/shell/tes/deepak/shell >bash
bash-3.00$ cut -d '
> ' -f 3 file
this is 1st line
this is 2nd
this is 3rd line
this is 4th line

bash-3.00$ ksh
$ cut -d '
> ' -f 3 file
this is 1st line
this is 2nd
this is 3rd line
this is 4th line
$


Last edited by Scott; 12-17-2010 at 08:03 AM.. Reason: Please use code tags
# 5  
Old 12-17-2010
Try:
Code:
cut -d$ -f3 file

R0H0N
# 6  
Old 12-17-2010
cut -d$ -f3 file it doesnot work tooSmilie
# 7  
Old 12-17-2010
Code:
xargs -d"|" < inputFile | cut -d"|" -f3

R0H0N
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