To be honest i don't understand what you intend the sed's to do. What they actually do is to reduce the file to its first line. A "head -1" would do the same, no?
Further, there is a problem when you try to expand variables which contain blanks, because blanks are special to the shell: they separate "fields", individual parts of the input line. I will show this in an example, which actually happened in a shipped version of AIX (see the full story here):
First a word of caution: create a separate directory for this to try it out, you will see why.
Suppose you want to redirect the output of a process to a file and you want to be flexible about it, so you put it into a variable: instead of
you write in your script:
This will work perfectly and as expected. (When you try this replace "command" with any UNIX command - "ls -l" will do, for instance.) But now suppose you want to include the error channel in your redirect too and you do it this way:
What will happen? For the shell, the content of "$destination" is one word and it will redirect only the <stdout> - [i]but to a file named "file 2>&1". (This is why i told you to create a separate directory for this - you can easily remove this directory instead of having to find out how to delete files with special characters.)
How this might function? There are two possible solutions: first, create your variables so that the blanks are outside:
Second possibility: use "eval". The reason why the shell has problems is that it parses the lines in a fixed procedure. When variables are expanded, they are all expanded together and no second pass is given to them (this is why it isn't possible to have a variable point to another variable with "normal" means). But "eval" restarts this evaluation process and this makes the shell "reconsider" the line with the now expanded blanks in it:
Btw.: you should really REALLY stay away from the backticks. They are only supported for backwards compatibility reasons and their use is discouraged. Only use the subshell "$(...)".
OK... I'm fairly new to unix having the admin handed to me on a platter w/almost no training.
However, being a programmer, I do pick up things fairly easily, but this one is getting the best of me.
I have a unix server that runs multiple versions of the same ERP system, hand crafted for our... (1 Reply)
Hello all:
I have a following textfile data with name inst1.txt
HDR|ABCD|10-13-2008 to 10-19-2008.txt|10-19-2008|XYZ
DTL|H|5464-1|0|02-02-2008|02-03-2008||||F|||||||||
DTL|D|5464-1|1|02-02-2008|02-03-2008|1||JJJ
DTL|D|5464-1|2|02-02-2008|02-03-2008|1||JJJ... (9 Replies)
Hi,
I want to replace a field in a text delimited file with the actual number of records in the same file.
HDR|ABCD|10-13-2008 to 10-19-2008.txt|10-19-2008|XYZ
DTL|0|5464-1|0|02-02-2008|02-03-2008||||F|||||||||
DTL|1|5464-1|1|02-02-2008|02-03-2008|1||JJJ... (3 Replies)
Hi Guys I have a question about filling up an array
I have a file called USER_FILE.txt
it contains the following:
Real Name:Thomas A Username:THOMAS_A
Real Name:Thomas B Username:THOMAS_B
Real Name:Thomas C Username:THOMAS_C
Real Name:Thomas D Username:THOMAS_D
Real Name:Thomas E... (8 Replies)
I have a string of commands I am piping some data through and I want to allow command line switches to select which commands are used. I want to do something like this: OPTION="| command3"
command1 -a -b c.txt | command2 -d -e $OPTION >result.txt
I want to do it that way because OPTION may be... (1 Reply)
hello all
i request you to give the solution for the following problem..
I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print
g
go
goo
goog
googl
google
like this Using unix Shell scripting...
without using... (1 Reply)
hi i am having issues with extra pipe.
i have a data file and i need to remove the extra pipe in the(example 4th and 7thline) in datafile. there are many other line and filed like this which i need to remove from files. The sample data is below:
270 31|455004|24/03/2010|0001235|72
271... (3 Replies)
Hello,
I am trying to make a bash script that can pull data from a file and then change one part of said data.
I want to search by username and pull the full line. That way there is a way to replace just one part of that line then return it back to the file.
My Data is stored like:
... (1 Reply)
this is Korn shell unix.
The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Hello,
I have standard loop
while read -r info; do
command $info
done < info
in info text file I have multiple commands each on line that I want to execute. When I used them in console they worked, but not with this loop.
This is one of the commands in info file:
grep... (4 Replies)