Cut fields between delimiters

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cut fields between delimiters
# 1  
Old 01-25-2014
Cut fields between delimiters

I'm having bother getting both lines contained in a file to output as the same value.

A simple example:


cut -d: -f1,4 input file


^ first line should be same as second.

trick one for me, i know why it's because of the extra delimiter in the first line, though is there away around this in a single command, or with some sed/awk fu

Help appreciated. Smilie

Last edited by Scrutinizer; 01-26-2014 at 05:01 AM.. Reason: code tags also for data
# 2  
Old 01-25-2014
awk -F: '{ print $1 FS $NF }' file

# 3  
Old 01-25-2014
Originally Posted by Yoda
awk -F: '{ print $1 FS $NF }' file

Magic, Thank you Smilie
# 4  
Old 01-25-2014
I dont know a better way to 'show':

echo "john:123456:123:456:doe
john:123456:123:doe"|sed s,":456","",g|cut -d: -f1,4

In case of a file it'll be more like:
grep john /input/file|sed s,":456","",g|cut -d: -f1,4

# 5  
Old 01-25-2014
No need to pipe output through so many commands, you could do the whole thing in sed:
sed 's#:.*:#:#' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut between two delimiters, / and .

BASH : I have a very long list I am parsing through: 10/10/19... (5 Replies)
Discussion started by: jeffs42885
5 Replies

2. Shell Programming and Scripting

Getting fields from a file having multiple delimiters

Hi All, I have a file with a single row having the following text ABC.ABC.ABC,Database,New123,DBNAME,F,ABC.ABC.ABC_APP,"@FUNCTION1("ENT1") ,@FUNCTION2("ENT2")",R, I want an output in the following format ABC.ABC.ABC DBNAME ABC.ABC.ABC_APP '@FUNCTION1("ENT1")... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

3. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

4. Shell Programming and Scripting

Cut counting consecutive delimiters as fields

When cut encounters consecutive delimiters it seems to count each instance as a field, at least with spaces. Is this typical behavior for any delimiter? #:~$ ifconfig eth0 | grep HWaddr eth0 Link encap:Ethernet HWaddr 94:de:80:a7:6d:e1 #:~$ ifconfig eth0 | grep HWaddr | cut -d " " -f... (6 Replies)
Discussion started by: Riker1204
6 Replies

5. Shell Programming and Scripting

awk: Print fields between two delimiters on separate lines and send to variables

I have email headers that look like the following. In the end I would like to accomplish sending each email address to its own variable, such as:'''''' etc... I know the sed to get rid of... (11 Replies)
Discussion started by: tay9000
11 Replies

6. Shell Programming and Scripting

Inserting additional comma delimiters in a csv file, after and before certian fields.

Hello I have a csv file which I need to insert addtional commas into. The csv is of the format field1,field2,field3,field4,...etc...,field13,field14 I need to add extra commas in each record so that the final output looks like ... (1 Reply)
Discussion started by: kamal_p_99
1 Replies

7. Shell Programming and Scripting

cut -- line with no delimiters

I just discovered, to my dismay, the following part of the cut man page: -f, --fields=LIST select only these fields; also print any line that contains no delimiter character, unless the -s option is specified The -s option toggles the printing of lines with no delimiters. In most... (3 Replies)
Discussion started by: chlorine
3 Replies

8. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

9. Shell Programming and Scripting

Cut based on Two Delimiters at one go

Hi I wanted to cut the feilds comming after % and After $ at one go can we do some thing like this cut -f 2 -d "%|$" (But it doesnot work) Input File BWPG %TCPRP1 $SCSPR000 BWPH %TCPRP1 $SCSPR003 BWPI %TRTYUP ResourceDescription="IMPRIMANTE " $BWOPTY BWPJ %ZOMBIE ... (4 Replies)
Discussion started by: pbsrinivas
4 Replies

10. Shell Programming and Scripting

Cut Last 3 Fields

I have a text: dsj khfksjdh <time> EST 2006 ab cgnr jkkjt <time> EST 2006 gfhdgjghg <time> EST 2006 fkdjh kjhsekjrh kdjhfkh jhdfkhfdkjh kjdf <time> EST 2006 In the above file i need to extract time from every line... which is always the third from the last... Pls help! Cheers, Bouren (4 Replies)
Discussion started by: bourne
4 Replies
Login or Register to Ask a Question