cut -- line with no delimiters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut -- line with no delimiters
# 1  
Old 09-02-2009
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 cases, I would like lines with no delimiters to be considered as lines with a single field, so that:
Code:
$ echo "a" | cut -d' ' -f 1

would output a,
and
Code:
$ echo "a" | cut -d' ' -f 2

would output an empty line.

Is there an alternate version of cut where this is possible, or an option I don't know about?
As far as I understand, there is no option of cut that would return an empty line in the second case: if I use the -s option there is no line of output.

I can always use awk but in many cases this is not practical for me.
# 2  
Old 09-02-2009
using awk, you can better handle these kind of situations.
# 3  
Old 09-03-2009
Thanks, but as I said in many cases awk is not as practical as cut, so I was hoping for a solution using cut or something very similar.

For instance, I don't think there's an easy way in awk of printing all files, starting from the second for instance? (the equivalent of -f2- in cut)
# 4  
Old 09-08-2009
i guess cut is not your way. i would use awk in cases like these.
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

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

3. UNIX for Dummies Questions & Answers

Cut fields between delimiters

I'm having bother getting both lines contained in a file to output as the same value. A simple example: john:123456:123:456:doe john:123456:123:doe cut -d: -f1,4 input file john:456 john:doe ^ first line should be same as second. trick one for me, i know why it's because of the... (4 Replies)
Discussion started by: landofus
4 Replies

4. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

5. Shell Programming and Scripting

reading line by line and cut

I have a file like name file.txt whose contents are 3 fields separated by colon':' . somewhat like code/OR_R1400_RC4/BM_ATEMP_11.0.1.33:28/01/2010:N code/OR_R1400_RC5/BM_ATEMP_11.0.1.35:28/01/2010:Y code/OR_R1400_RC4/BM_ATEMP_11.0.1.33:29/01/2010:N... (8 Replies)
Discussion started by: gotam
8 Replies

6. Shell Programming and Scripting

How to cut specific line and one line under?

Hi guys, I need to analyze the following alert log file: Beginning log switch checkpoint up to RBA , SCN: 3916025539605 Sat May 1 00:54:52 2010 Thread 1 advanced to log sequence 271423 (LGWR switch) Current log# 1 seq# 271423 mem# 0: /dw/stg_redo01/log_dwstg_g1_m1.log Current log# 1... (7 Replies)
Discussion started by: nir_s
7 Replies

7. Shell Programming and Scripting

cut a string in a textfile line per line

i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths) i have a for loop that gets the string line per line, then each line has to be compared: for x in `cat tmp2.txt`; do if; then echo 'BAC' elif ... (6 Replies)
Discussion started by: izuma
6 Replies

8. Shell Programming and Scripting

cut in line

hi how can i get from Komendant st. house 50 ex. 1 fl. 1000 to > Kome.50.2.1000 Elsestreet house 51 ex. 2 fl. 11 to > Else.51.2.11 ??? (4 Replies)
Discussion started by: Trump
4 Replies

9. UNIX for Dummies Questions & Answers

Script to find the number of tab delimiters in a line

Hi, I need to find the number of tab delimiters in the first line of a file.So using word=`head -1 files.txt` I have extracted the first line of file into a variable word.It has 20 tab delimted columns.So can anyone help me in finding the number of delimiters? I am using csh and I am a... (5 Replies)
Discussion started by: poornimajayan
5 Replies

10. 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
Login or Register to Ask a Question