I am writing a script to remove multiples pipes (|) from a file. It needs to look like this data|data|data
instead of data|||data||data||||data
I have found the correct sed command to do this, but I need to do it in a loop and a for loop has not worked for me. It needs to be done on multiples files and then write to a new file. I'm running Solaris 8. I believe I need to use a while loop, but am unsure how do do this.
Here is what I have thus far:
#!/bin/sh
file="/file/directory/bin/temp/*.fixed"
#Removes extra spaces and Pipes in the file
for filename in *.fixed
do
sed 's/ * //g;s/||/|/g;s/|||/|/g' $file > newFile.fixed
done
sed 's/ * //g;s/||/|/g;s/|||/|/g' $file > newFile.fixed
more or less. The following will catch not only double and triple occurences of pipe-chars, but any number exceeding 1 (only the sed-code):
s/|[|]*/|/g
This replaces 1 or more occcurence of a pipe-char with exactly 1. The "[...]" means "any of the characters inside the brackets" and "*" means "zero or more of the last-mentioned expression", which is the brackets in this case. "[abc]*" would match any number of the characters a, b and c, i.e. "cbaabbc" or "a", but not "d".
About the multiple files issue, yes, you will have to use a loop. You can use the for-loop you have mentioned, but there will be a problem it the directory contains a very big number of files. "*" expands to a list of all filenames and this could get bigger than the maximum command line length in UNIX (for POSIX systems this is IIRC 4k, see /usr/include/sys/limits.h). You can overcome this by either using a temporary file:
I'm trying to remove the first match only of 2Z694 from an xml file and replace with a blank
File Example:
</Phoenix_Response_Data>
<Bundle_Name_Primary>2Z694</Bundle_Name_Primary>
<Bundle_Name>2Z694</Bundle_Name>
</Phoenix_Response_Data>
tried using:
sed -e 's/'2Z694'/''/1' but this... (15 Replies)
I have a script that I am trying to apply on files that have form feeds between pages but I am trying to replace the last form feed, with carriage return so that when I convert it to a PDF file it won't generate a blank page.
My script looks like this
sed '$ s/\^L/\^M/' invoice.txt... (12 Replies)
Hello all,
I have a file like this
AA||
BB||
CC||
I want to remove the pipelines (||) from the last occurrance of them in file.
that means after removal my file should be like this
AA||
BB||
CC
how can we achieve this? (2 Replies)
Hi
i need to remove all the lines staring with 'printf("\n' from a file,
example : the file tmp.txt contains
printf("\n ");
printf("\n good");
printf("\n ");
printf("\n ");
printf("");
printf(
m_sprintf(for
printf("\n ");
i have tried with following commands but... (5 Replies)
i need to search for user belonging to group 'macusr' and the extract the user name .
i am able to write a oneliner for this using awk + sed + tr
i am using tr to chop off '()' from the output. but i want to use it in sed itself . can someone please help me with that
file contents
... (7 Replies)
Hi
Trying to remove line from file log_January_1_array and code below doesn't work.
$(sed -e '/"$n"/d' <log_January_1_array >log_January_1_array_1)
sed doesn't know what is in $n variable and nth happens.
Please advice how to make sed running this.
thx (2 Replies)
Hello and thx for reading this
I'm using sed to remove only the leading spaces in a file
bash-280R# cat foofile
some text
some text
some text
some text
some text
bash-280R#
bash-280R# sed 's/^ *//' foofile > foofile.use
bash-280R# cat foofile.use
some text
some text
some text... (6 Replies)
Hi,
Please help me on this.
I am creating a named pipe in a kshell script.
I am using mkfifo pipe_name command to create the pipe.
I want to remove the named pipe after my work is completed.
How can i do that. (8 Replies)
i tried the following:-
sed -e file 's/^@//g' > temp
also tried
sed -e file 's///g' > temp
nothing happened....can someone please tell me wht is wrong???
also someinformation abt the character "^@"(it is ONLY ONE character and NOT TWO characters)
thanx in advance.. (13 Replies)