Problem with the script!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with the script!!!
# 1  
Old 10-31-2013
Problem with the script!!!

Fragement of the Script:

________>
Code:
awk 'BEGIN{OFS=FS="|"} {$11="";print } ' < $1 > tempd0217
sed 's/||/|/11g' tempd0217 > $1

_________>

I am trying to replace || with | at 11th Feild in a flat file, the sed command its not only replacing 11th feild but also other feilds as well whereever it finds ||| or ||

Request to let me know the best way to replace 18th feild only

Flat file example:
Code:
492|8243848|13586071||68|LYNMOUTH DRIVE||RUISLIP|MIDDLESEX|HA4 9BZ||7|||
492|8243848|13586072||68|LYNMOUTH DRIVE||RUISLIP|MIDDLESEX|HA4 9BZ||7||
492|8243848|13586073||68|LYNMOUTH DRIVE||RUISLIP|MIDDLESEX|HA4 9BZ|7||||


Last edited by Franklin52; 10-31-2013 at 06:11 AM.. Reason: Please use code tags
# 2  
Old 10-31-2013
Can you post your input sample and expected output sample ?
Not clear from your previous post because you start with 11 the field , later with 18th field.

This works for 4th occurrence ( example ) :
Code:
sed -e 's/||/|/4' input

cat input:
Code:
one||two||3||4||5||6

output:
Code:
one||two||3||45||6

# 3  
Old 10-31-2013
Sorry for that,

In input file after the |HA4 9BZ| we have || and that needs to be replaced with | through out the file:


Input file:
Code:
492|8243848|13586071||68|LYNMOUTH DRIVE||RUISLIP|MIDDLESEX|HA4 9BZ||7|||
492|8243848|13586072||68|LYNMOUTH DRIVE||RUISLIP|MIDDLESEX|HA4 9BZ||7||

Expected output:
Code:
492|8243848|13586071||68|LYNMOUTH DRIVE||RUISLIP|MIDDLESEX|HA4 9BZ|7|||
492|8243848|13586072||68|LYNMOUTH DRIVE||RUISLIP|MIDDLESEX|HA4 9BZ|7||


Last edited by Franklin52; 10-31-2013 at 06:12 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 10-31-2013
Code:
sed -e 's/||/|/3' input

or if the string is constant:
Code:
sed -e 's/HA4 9BZ||/HA4 9BZ|/' input

# 5  
Old 10-31-2013
Nope that won't work
sed 's/||/|/3' would only replace 3 feild in a line

and

sed 's/||/|/3g' would do it all through the file,

Is there any other way to remove || and place | at specific feilds,

Last edited by Scott; 10-31-2013 at 10:05 AM.. Reason: Use code tags, please...
# 6  
Old 10-31-2013
Deleting a delimitier is equivalent to concatenating adjacent fields. In this case, since one of the fields is empty, it's equivalent to extracting the empty field. If that is always the case:
Code:
cut -d\| -f 1-10,12-

If that doesn't apply, then you need to do a better job of specifying your data.

Also, note that each of your posts has been edited by staff for code tags. Take the hint and use them for code and data samples.

Regards,
Alister
# 7  
Old 11-01-2013
Question

Yep Alister, I got into this forum for the first time, I will take up the hits as per the suggestions,

Let me try the command you provided and will get back to you,

Thanks very much,

---------- Post updated 11-01-13 at 04:03 AM ---------- Previous update was 10-31-13 at 08:52 AM ----------

Nope the above command as well is not working Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in calling a script inside a script

Hi team, I have a script in different folder. Now i want to call that script and execute that script from that path alone. My code is #!/bin/bash wname=yahoo PATH='/opt/IBM' wac=`/usr/bin/ls $PATH | /usr/bin/grep "$wname"` STOP=`/usr/bin/find $PATH/$wac -type f -name "stop.sh"`... (8 Replies)
Discussion started by: natraj005
8 Replies

2. Shell Programming and Scripting

Shell script newbie, what is problem with my script?

Hello, Ubuntu server 11.10 can anybody help what is problem with my shell script? #!/bin/bash #script to find out currently logged on user is root or not. if ] then echo "You are super" else echo "You are awesome!" fi When I run script, I get following output ./uid: line 3: I... (4 Replies)
Discussion started by: kaustubh
4 Replies

3. Shell Programming and Scripting

Problem while calling a script within a script

Hi , I have moduled my scripts in three scripts . From First script i am calling second and from second i am calling third for some check . Problem is with the third script call. ---In second script EXP ='test.\abc.\Server.*abc.xml.*' pid=$($HOME/bin/checkpid $EXP) --Third... (2 Replies)
Discussion started by: amrishn
2 Replies

4. Shell Programming and Scripting

Problem running a program/script in the background from a script

Hi all, I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes... (5 Replies)
Discussion started by: newbie_01
5 Replies

5. Shell Programming and Scripting

Problem with a script

Hi everyone, I got a problem with a script. What it's supposed to do is: to take as arguments a directory name <dir> and a dimension (in byte) <dim>; if <dir> exists, to write name and dimension of every regular file within it that sizes lesser than <dim> in regFileList. Nothing happens... (10 Replies)
Discussion started by: Luke Bonham
10 Replies

6. UNIX for Dummies Questions & Answers

Problem with script

Hello All. I have a script that is suppossed to start up a daemon but when executed, simply hangs. Could you please take a look and let me know where the problem might be? TIA ################################################################### # # SCRIPT: dstart3000.sh # Bring up the Domain... (6 Replies)
Discussion started by: grin1dan
6 Replies

7. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./try.sh $t $d $m'); in shell scipt try.sh i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies

8. Shell Programming and Scripting

ssh script problem problem

Hi Please help me with the following problem with my script. The following block of code is not repeating in the while loop and exiting after searching for first message. input_file ========== host001-01 host001-02 2008-07-23 13:02:04,651 ConnectionFactory - Setting session state... (2 Replies)
Discussion started by: pcjandyala
2 Replies

9. Shell Programming and Scripting

Help. Script problem

hey guys. i have a bunch of programs in a script that needs to run as root and the rest as another user, we'll call him gabriel. now, in this script, i want to run the first few lines as root. now, how do i, after running as root, tell the script to run the remaining lines as the user gabriel?... (3 Replies)
Discussion started by: Terrible
3 Replies

10. UNIX for Dummies Questions & Answers

Problem starting a script from a 'main'-script

Please Help! :o I have a main script (ksh) where another script is called (convert_picture). Normally this works ok, but since some changes has been made on the unix-server (I dont know what :( ) suddenly it doesnt work anymore: i get an error message: ksh: convert_picture not found. I am... (3 Replies)
Discussion started by: Rakker
3 Replies
Login or Register to Ask a Question