HELP WITH SEARCH AND SUBSTITUTE IN "|" DELIMITED FILE


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HELP WITH SEARCH AND SUBSTITUTE IN "|" DELIMITED FILE
# 1  
Old 04-01-2012
Question HELP WITH SEARCH AND SUBSTITUTE IN "|" DELIMITED FILE

Hi

I have a "|" delimited file as shown below.

Code:
55987|2011-04-07|09:30: 8.0|09:30:27.4|9194
55988|2011-04 07|09:30:21.0|09:30:27.4|9199
55989|2011-04-07|09:30:25.0|09:30:27.5|9176
55990|2011-04-07|09:29:33.0|09:30:27.5|9196
55991|2011-04-07|09:30:21.0|09:30:27.5|9199
55992|2011-04-07|09:30:27.0|09:30:27.5|9195

I want " .0 " and " .4 " , " .5 " be removed from column 3rd and 4th respectively.So that my records should be like ...

Code:
55987|2011-04-07|09:30: 8|09:30:27|9194
55988|2011-04 07|09:30:21|09:30:27|9199
55989|2011-04-07|09:30:25|09:30:27|9176
55990|2011-04-07|09:29:33|09:30:27|9196
55991|2011-04-07|09:30:21|09:30:27|9199
55992|2011-04-07|09:30:27|09:30:27|9195

Help me in this regard.

Thanks

Moderator's Comments:
Mod Comment Welcome to these forums. Please use [code][/code] tags for script and data sample....

Last edited by Scrutinizer; 04-01-2012 at 07:44 PM..
# 2  
Old 04-01-2012
The simple way, assuming that there are not any other .n values that you want to keep:
Code:
 /usr/bin/sed 's/[.][0-9]//g' input-file >output-file

# 3  
Old 04-01-2012
Thanks a lot AGAMA.... It really worked. Thanks a lot indeed...
# 4  
Old 04-01-2012
Two more complicated and more precise methods if it really needs to be at the end of column3 and column4 only:
Code:
awk '{sub(pat,x,$3);sub(pat,x,$4)}1' pat='\.[0-9]$' FS=\| OFS=\| infile

Code:
sed 's/\(\.[0-9]\)\{0,1\}|/|/3;s/\(\.[0-9]\)\{0,1\}|/|/4' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search file containing ps results for a match "my.cnf" and then for a second match . "ok:" and

I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for: my.cnf /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Removing duplicates on a single "column" (delimited file)

Hello ! I'm quite new to linux but haven't found a script to do this task, unfortunately my knowledge is quite limited on shellscripts... Could you guys help me removing the duplicate lines of a file, based only on a single "column"? For example: M202034357;01/2008;J30RJ021;Ciclo 01... (4 Replies)
Discussion started by: Rufinofr
4 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help

Hi, I am on a Solaris8 machine If someone can help me with adjusting this awk 1 liner (turning it into a real awkscript) to get by this "event not found error" ...or Present Perl solution code that works for Perl5.8 in the csh shell ...that would be great. ****************** ... (3 Replies)
Discussion started by: andy b
3 Replies

6. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

how to create flat file delimited by "\002"

I need to create a flat file with columns delimited by "\002" (octal 2) I tried using the simple echo. name="Adam Smith" age=40 address="1 main st" city="New York" echo ${name}"\002"${age}"\002"${address}"\002"${city} > mytmp but it creates a delimiter with different octal... (4 Replies)
Discussion started by: injey
4 Replies

9. Shell Programming and Scripting

How to substitute "\" by "\/" using SED?

Input: a/b/c Output required: a\/b\/c This does not work: sed s/'\/'/'\//'/g (6 Replies)
Discussion started by: indianjassi
6 Replies

10. Shell Programming and Scripting

sed substitute / for \ : error "Function can not be parsed"

Hello all, I have a weird issue when trying to substitute the slashes into backslashes. If I execute this on the command-line (bash / ksh) I get the path correctly translated with backslashes instead of slashes. > echo $PWD | sed 's/\//\\/g' However, when I put this in my script to... (3 Replies)
Discussion started by: candyflip2000
3 Replies
Login or Register to Ask a Question