Hi,
When i am running a script it considers the below as mulitple arguments.
There is any command which can ignore the spaces.
I tried by using sed like below to ignore but it doesnt work.
sed 's/ /\\ /g'
100% Haddock Fillets Battered 500G-small.gif
~vino
As it is not so clear, am assuming the following.
$ cat t.sh
echo $1 $2
$ sh t.sh '100% Haddock Fillets Battered 500G-small.gif' 'another file'
100% Haddock Fillets Battered 500G-small.gif another file
$ sh t.sh 100% Haddock Fillets Battered 500G-small.gif another file
100% Haddock
You need to quote your arguments finally... GOT ?
I need a command to ignore the white spaces when reading a file.
Which contains contents like below.
Where i will be reading each line and passing as a argument to another process.
Due to this space its throwing multiple arguments error.
products/100% Haddock Fillets 500G-small.gif
products/100% Haddock Fillets 500G.gif
products/2 Hot and Spicy Grills 200G -small.gif
products/2 Hot and Spicy Grills 200G.gif
products/2 Original Fillet Burgers 180G -small.gif
products/2 Original Fillet Burgers 180G.gif
Quote it from where you are sending.... Again quoting is the answer.
Example:
Process 1: Get and prints the argument.
$ cat get-arg.sh
echo $1 $2
File: f1 is the file which has the given content
$ cat f1
products/100% Haddock Fillets 500G-small.gif
products/100% Haddock Fillets 500G.gif
products/2 Hot and Spicy Grills 200G -small.gif
products/2 Hot and Spicy Grills 200G.gif
products/2 Original Fillet Burgers 180G -small.gif
products/2 Original Fillet Burgers 180G.gif
Process 2: Reads lines, and calls the other process with the argument.
$ cat t1.sh
while read line
do
#echo $line
sh ./get-arg.sh "$line"
done < ./f1
Note: When "" around line is there then it had been taken as a single argument...
I hope you have got it now as because i demonstrated enough ....
If needed, give without QUOTE in $line, then you will printing only first two words...
With Quote:
$ sh t1.sh
products/100% Haddock Fillets 500G-small.gif
products/100% Haddock Fillets 500G.gif
products/2 Hot and Spicy Grills 200G -small.gif
products/2 Hot and Spicy Grills 200G.gif
products/2 Original Fillet Burgers 180G -small.gif
products/2 Original Fillet Burgers 180G.gif
Without Quote:
$ sh t1.sh
products/100% Haddock
products/100% Haddock
products/2 Hot
products/2 Hot
products/2 Original
products/2 Original