Cutting fields from lines with multiple spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cutting fields from lines with multiple spaces
# 1  
Old 09-07-2011
Cutting fields from lines with multiple spaces

Please see the following code, between "status" and "OK" exists many spaces, I want to get
Code:
status                        OK

. how to ignore multi spaces? If tab exists in the spaces, how to ignore it ?
Is there other commands can replace cut?
Code:
[river@localhost CLI008003]$ echo 'drv status                        OK'| cut -d " " -f 2-3
status 
[river@localhost CLI008003]$ echo 'drv status                        OK'| cut -d " " -f 2-
status                        OK
[river@localhost CLI008003]$ echo 'drv status                        OK'| cut -d " " -f 3

[river@localhost CLI008003]$

# 2  
Old 09-07-2011
You can't do it with cut, but awk is a perfect tool for it:
Code:
awk '{print $2, $3}'

# 3  
Old 09-07-2011
However, awk can not print the content between $2 and $3.
# 4  
Old 09-07-2011
Quote:
. how to ignore multi spaces? If tab exists in the spaces, how to ignore it ?
Smilie You asked about ignoring and not about preserving spaces and tabs.
Use sed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: Combine multiple lines based on number of fields

If a file has following kind of data, comma delimited 1,2,3,4 1 1 1,2,3,4 1,2 2 2,3,4 My required output must have only 4 columns with comma delimited 1,2,3,4 111,2,3,4 1,222,3,4 I have tried many awk command using ORS="" but couldnt progress (10 Replies)
Discussion started by: mdkm
10 Replies

2. UNIX for Dummies Questions & Answers

cutting multiple columns into multiple files

Hypothetically, suppose that file1 id v1 v2 v3 v4 v5 v6 v7..........v100 1 1 1 1 1 1 2 2 .....50 2 1 1 1 1 1 2 2 .....50 3 1 1 1 1 1 2 2 .....50 4 1 1 1 1 1 2 2 .....50 5 1 1 1 1 1 2 2 .....50 I want to write a loop such that I take the id# and the first 5 columns (v1-v5) into the... (3 Replies)
Discussion started by: johnkim0806
3 Replies

3. Shell Programming and Scripting

replacing a quote in some lines with multiple quote fields

i want to replace mistaken quotes in line starting with tag 300 and relocate the quote in the correct position so the input is 223;25 224;20100428064823;1;0;0;0;0;0;0;0;8;1;3;9697;18744;;;;;;;;;;;; 300;X;Event:... (3 Replies)
Discussion started by: wradwan
3 Replies

4. Shell Programming and Scripting

bash script too many fields wraps to multiple lines

Hello. I'm trying to write a script to take a 5 field file, do some math, and extend it to 9 fields. Problem is, the script keeps wrapping it to two lines, even tho 9 fields, tab separated (even comma separated) doesn't fill the screen. Even if it did, I'm eventually copying it to an excel ... (2 Replies)
Discussion started by: JoeNess
2 Replies

5. AIX

missing blank spaces while cutting the file to individual files

$ indicates blank space file1.txt: 001_AHaris$$$$$020$$$$$$$$$ 001_ATony$$$$$$030$$$$$$$$$ 002_AChris$$$$$090$$$$$$$$$ 002_ASmit$$$$$$060$$$$$$$$$ 003_AJhon$$$$$$001$$$$$$$$$ $ indicates blank space code while read "LINE"; do echo "$LINE" | cut -c6- >> $(echo "$LINE" | cut... (1 Reply)
Discussion started by: techmoris
1 Replies

6. Shell Programming and Scripting

cutting lines

Dear All, Is there a way to cut the lines that have been "head" Here is what i m trying to do Please advice there is file name dummy.txt now i am trying to head this file 4 time by using a loop and every time this file is head with different values e.g in first instance it will... (7 Replies)
Discussion started by: jojo123
7 Replies

7. Shell Programming and Scripting

join on a file with multiple lines, fields

I've looked at the join command which is able to perform what I need on two rows with a common field, however if I have more than two rows I need to join all of them. Thus I have one file with multiple rows to be joined on an index number: 1 randomtext1 2 rtext2 2 rtext3 3 rtext4 3 rtext5... (5 Replies)
Discussion started by: crimper
5 Replies

8. Shell Programming and Scripting

cutting fields and doing trim in awk

hi, I have this code: #!/usr/bin/ksh #SERVICES gzcat *SERVICES* | awk ' { SUBSCRIBERNUMBER=substr($0,1,20) SUBSCRIBERNUMBER=trim(SUBSCRIBERNUMBER) SERVICECODE=substr($0,22,61) SERVICECODE=trim(SERVICECODE) STARTDD=substr($0,63,72) STARTDD=trim(STARTDD) STARTDT=substr($0,74,81)... (1 Reply)
Discussion started by: naoseionome
1 Replies

9. UNIX for Dummies Questions & Answers

Need help cutting a couple of fields from log file.

Data begins as such; Mar 16 03:27:05 afzpimdn01 named: denied update from .3983 for "nnn.nnn.in-addr.arpa" IN Mar 16 03:27:37 afzpimdn01 named: denied update from .4844 for "nnn.nnn.in-addr.arpa" IN Mar 16 03:27:56 afzpimdn01 named: denied update from .2650 for "nnn.nnn.in-addr.arpa" IN ... (4 Replies)
Discussion started by: altamaha
4 Replies

10. UNIX for Dummies Questions & Answers

Cutting the top two lines, and also charachters below.

Hey all. I have a file that I am trying to cut information out of. We have a script that shows us all of our Radio Scanners that are being used and I'm writing a script that clears all of the context off of the scanners. The script that runs shows us this information below... |emp_id ... (5 Replies)
Discussion started by: jalge2
5 Replies
Login or Register to Ask a Question