sed command to delete points in a certain colum


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command to delete points in a certain colum
# 1  
Old 04-27-2009
sed command to delete points in a certain colum

Dear Unix users,

I have a (I think simple) question;

I have a file (out.dat) like below,
the file contains some line which include 'LOS' string.
.
LOS 46.5360 91.0220 200708.2515.4900. 5400 64 1100010
.
.
I would like to delete the points in 4th column.

When I used the below sed command:
Code:
sed -e '/LOS/s/\.//g' out.dat

it gives
.
LOS 465360 910220 20070825154900 5400 64 1100010
.

it deletes all the points in the line.

How can I specify that I only want to delete the points at 4th column (i.e 200708.2515.4900.)

Thank you very much,
Murat

Last edited by Yogesh Sawant; 04-27-2009 at 03:04 PM.. Reason: added code tags
# 2  
Old 04-27-2009
Try this :-

Code:
awk '/LOS/ {gsub(/\./,"",$4);print}' <out.dat

On solaris i had to use /usr/xpg4/bin/awk
# 3  
Old 04-27-2009
Hi lavascript,

Thank you very much for your reply.

your command worked, however my out.dat file contains
other lines besides the ones begin LOS. So your comment
change only lines begin with LOS and print only these lines.

...
565 233 33
LOS 46.5360 91.0220 200708.2515.4900. 5400 64 1100010
333 20
123 20 330 20
233
...

How can I print other lines as well?.
Thank you very much

Last edited by Yogesh Sawant; 04-27-2009 at 03:05 PM.. Reason: removed the unnecessary link
# 4  
Old 04-27-2009
Code:
awk '/LOS/ {gsub(/\./,"",$4);print}'

Should be:

Code:
awk '/LOS/ {gsub(/\./,"",$4)}{print}'

# 5  
Old 04-28-2009
Code:
nawk '{
        gsub(/\./,"",$4)
        print
        }' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete line from file using sed command?

hello Team, I want to delete below linux using sed command but I am getting error.sed -i '/url=/status.cgi?hostgroup=/d' 3 error:sed: -e expression #1, char 32: unknown option to `s' Could you please help me with correct syntax. My line contain / character because of that I am getting... (4 Replies)
Discussion started by: ghpradeep
4 Replies

2. Shell Programming and Scripting

sed command to delete a pattern in a file

Hi Everyone, I have an unusual requirement. Here is where i am stuck for sometime now... I have this text file.. lets say .. output.sql... it has lot of entries... here below is part of the entry... .. . . . . . . . . . . . . . . . .... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

sed command to delete everything after > on line

I have a large data file that I need to edit. There are lines like, > <IDNUMBER> (ST000002) > <SUPPLIER> (ST000002) > <IDNUMBER> (ST000004) > <SUPPLIER> (ST000004) and I need to delete everything after the >, excepting the end of line. > <IDNUMBER> > <SUPPLIER> > <IDNUMBER> > ... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

4. Shell Programming and Scripting

delete the line with a particular string in a file using sed command.

Hello, I want to delete all lines with given string in file1 and the string val is dynamic. Can this be done using sed command. Sample: vars="test twinning yellow" for i in $vars do grep $i file1 if then echo "Do Nothing" else sed `/$i/d` file1 fi done Using the above... (5 Replies)
Discussion started by: PrasadAruna
5 Replies

5. Shell Programming and Scripting

sed command to delete line

HI, Im using the below commmand to delete lines having "(" at the start of a line. sed -e '/^(/d' But i need a command to delete lines that has only "(" in it and no other strings. infile - asdf asdf ( asdf ( asd outfile (1 Reply)
Discussion started by: dvah
1 Replies

6. Shell Programming and Scripting

Delete a line between selected lines using sed or any other command

I want to delete a line between selected lines using sed: e.g. : Between "bus" to "pins", delete lines conaining "signal" word. Input : bus direction signal new signal old pins signal ok end Desired Output: bus direction pins signal end (4 Replies)
Discussion started by: nehashine
4 Replies

7. Shell Programming and Scripting

SED delete only first line command - Help need

Can any one help me how the sed delete only first line command (D) works. sed -f sedcmds File.txt In this how the sed delete only first line command (D) works to delete the blank lines appearing more than ones leaving only one blank and deleting others blanks. While doing step by step when... (2 Replies)
Discussion started by: gwgreen1
2 Replies

8. Shell Programming and Scripting

sed command to delete row

I want to use sed command to delete a matched row with a pattern. And I also want to delete previous and next row of that row. Which option can I use with sed ? (9 Replies)
Discussion started by: anhtt
9 Replies

9. Shell Programming and Scripting

sed or awk to convert text files with recurring headings to rows and colum

I have many text file reports generated by a Information Assurance tool that I need to get into a .CSV format or Excel tab delimited format. I want to use sed or awk to grab all the information in the sample text file below and create column headings:Risk ID, Risk Level, Category, Description, How... (5 Replies)
Discussion started by: Bjoeboo
5 Replies

10. Shell Programming and Scripting

What's wrong with this sed command? delete & append

I want to write a sed command that does the following work: file: <a>asdfasdf<\s> <line>hello</line> <b>adf<\c> <b>tttttttt<\c> output: name=hello sed -e 's/^*//' -n -e '/<line>/s/<*>//gp;' -e 's/^/name="/g' file but I can not append "=" after getting the line with... (5 Replies)
Discussion started by: minifish
5 Replies
Login or Register to Ask a Question