sed cut columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed cut columns
# 1  
Old 04-30-2012
sed cut columns

hello everyone !

i face the following problem as i use sed to ignore some columns of an output.
the command i use is
Code:
sed 's/^\([A-Za-z0-9]*\) \([A-Za-z0-9]*\).*/\1 \2/'

as i only want the 2 first columns the command finger returns

the problem is that for some lines the results are fine but for other lines
it only prints the 1 column and totally ignores the 2nd..

when i change the order like this
Code:
sed 's/^\([A-Za-z0-9]*\) \([A-Za-z0-9]*\).*/\2 \1/'

as i'm trying to find out what's wrong with these lines,the output of the column 1 is ok but for those lines column 2 did not appear before,now it appears as a white space.

thanks in advance

Last edited by Franklin52; 05-01-2012 at 03:55 AM.. Reason: Please use code tags
# 2  
Old 04-30-2012
Can you post sample input and desired output?
# 3  
Old 04-30-2012
can you post the sample input and output data
# 4  
Old 04-30-2012
yes the input is like this:

nickname name lastname date hour

and the desired output is

nickname name

the thing is that for some lines works fine and for others only

nickname

is shown, that's why i changed the order so the output turns out to be

name nickname

and for the lines with the problem the name is just a white space so i figured that's why it wasn't shown before
# 5  
Old 04-30-2012
can you post the sample input and output data
# 6  
Old 04-30-2012
i use finger command in order to see which users are logged in and the results


Login Name Tty Idle Login Time Office
ja James Adams pts/6 23 Apr 30 13:21 (:0)
kj Kim Jones tty10 Apr 30 14:06 (:0)


then i want only the column login and name
# 7  
Old 04-30-2012
Code:
finger | awk '{print $1,$2}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut line from searched file if grep find neighbor columns

Hello All, While searching for the question, I found some answers but my implementation is not giving expected output. I have two files; one is sourcefile, other is named template. What I want to do is to search each line in template, when found all columns, cut the matching line from source... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

AWK command to cut the desired header columns

Hi Friends, I have a file1 i want to retrieve only the fields which have DEP,CITY,TRANS as headers in other file. Output: I want to give the input as DEP,CITY,TRANS column names to get the output. i used cut command .. but if i have 300 fileds it is more difficult to... (4 Replies)
Discussion started by: i150371485
4 Replies

3. Shell Programming and Scripting

CSV with commas in field values, remove duplicates, cut columns

Hi Description of input file I have: ------------------------- 1) CSV with double quotes for string fields. 2) Some string fields have Comma as part of field value. 3) Have Duplicate lines 4) Have 200 columns/fields 5) File size is more than 10GB Description of output file I need:... (4 Replies)
Discussion started by: krishnix
4 Replies

4. Shell Programming and Scripting

Cut columns with delimiter

HI, I have a file like below "103865","103835","Zming","","Zhu","103965","Sunnyvale","US", "116228","116227","Morlla","","Kowalski","113228","Paese "(Treviso)""IT" I want to validate the 7th column which is below. "Sunnyvale" "Paese In the above 7th column Paese is not ended with... (9 Replies)
Discussion started by: Krrishv
9 Replies

5. UNIX for Dummies Questions & Answers

cut and paste columns using awk

Hi, Let's say that I have a file called table, I know that if I need to see a the second column for exampls I use: awk ' {print $2}' table.txt Is there anyway to use awk to actually cut a column and put it somewhere else in the table?:confused: (8 Replies)
Discussion started by: cosmologist
8 Replies

6. Shell Programming and Scripting

cut columns in everyline

Is there a betterway to cut certain columns in everyline based on positions. Basically, I have a largefile and eachline is of 1000 characters and I need to cut the characters 17-30, 750-775, 776-779, 780-805 while do fptr=`cat $tempfile | head -$i | tail -1` ... (4 Replies)
Discussion started by: gunaah
4 Replies

7. Shell Programming and Scripting

cut - columns with formatted Output

Hi I have the input file as below ***TEST10067 00567GROSZ 099 00567CTCTSDS90 ***TEST20081 08233GROZWEWE 00782GWERW899 ***TEST30088 08233GROZWEWE 00782GWERW899 I am finding the lines starting with *** and outputing as below TEST10067 TEST20081 TEST30088 I need a space between TEST1... (9 Replies)
Discussion started by: dhanamurthy
9 Replies

8. Shell Programming and Scripting

Help in SED and CUT.

Hi I have a file. In Each and every line, i want to cut the position from 130 to 134 and need to check if it is XXXX then i need to replace with YYYY (Only from 130 to 134). Your help is very much appriciated. (4 Replies)
Discussion started by: senthil_is
4 Replies

9. Shell Programming and Scripting

cut sed grep or other?

Hi Is there a way to cut the last two characters off a word or number given that this word or number can be of varying length? I have tried something like TEST=`echo $OLD | cut -c 1-5` where $OLD is a variable containing a number like 1234567 which gives a result of 12345. This is fine... (4 Replies)
Discussion started by: rleebife
4 Replies

10. Shell Programming and Scripting

SED and Cut question

I am trying to cut and delete using sed and redirect back into the file. This is not working write. When testing the script, it hangs. Any idea what I am doing wrong here. ################ Reads the input file to cut volumes for returns and CUT_ERVTAPE_FILE() { echo "working on cut... (2 Replies)
Discussion started by: gzs553
2 Replies
Login or Register to Ask a Question