First post, so I hope someone can help me with this weirdness
I have a number files with some rows of information I want to extract, at the same time I want to add to a string some details from the file. I have found two different ways of looping over rows in a file, but one method doesn't let me concatenarte strings and I don't know why....
The first method sets the IFS environmental variable. I don't really favour this method, but it works..
and produces:
catdogdogdogdogdogdogdogdogdogdogdogdogdogdogdogdo gdogdogdogdogdogdogdogdogdogdogdogdog
Method 2 uses "read" but prevents the concatenation of the string:
and produces:
cat
Why is there a difference in the two methods? I would rather not be changing environmental variables and a simple loop is my preferred choice.
Thanks for your help, as this has been driving me crazy...
Stephen
As Scrutinizer mentioned, with bash the commands after the pipe run in a subshell and variables in a subshell are not visible outside the block of code in the subshell and they are not accessible to the parent process.
You can avoid the use of a pipe (and useless use of cat) like:
I have a script which is migrated from AIX to Linux & now while running it is no able to concatenate string values
The string concatenation step under while loop is not displaying desired result
Please find below the piece of code:
while read EXT_FILE ; do
EXT_FILE=$EXT_FILE.ext.sent
echo... (7 Replies)
Hi Team!!
Please can anyone tell me why the following line does not work properly?
str3+=$str2
it seems that str3 variable does not keep its value in order to be concatenated in the next iteration! Thus when i print the result of the line above it returns the str2 value
What i want to do is to... (8 Replies)
Hello
I want to achieve the following.
However the concatenation is not working
mv `ls -ltr *myfile*.log|awk '{print $9}'` `ls -ltr *myfile*.log|awk '{print `date +'%d%m%y%k%M%S'` $9}'`
I tried
awk '{x=`date +'%d%m%y%k%M%S'` print $x "" $9}'
awk '{x=`date +'%d%m%y%k%M%S'`... (2 Replies)
Hi there,
I'm writing a basic script where I want to make a string of 2 numeric fields from a file, which I have done, but the behavior is rather confusing.
I have a file of random values such as:
1 2
3 4
5 6
7 8
9 10
and my awk code is:
BEGIN { FS = " " }
{ str = str $1 $2 }
END {... (7 Replies)
The string comparison highlighted below is not working fine. Please help:
while read line
do
# Get File name by deleting everything that preceedes and follows Filename as printed in cvs status' output
f_name=`echo $line | sed -e 's/^File://' -e 's/ *Status:.*//' | awk '{print $NF}'`
... (4 Replies)
Hi,
In the code included below, the string comparision is not working fine. Please help
while (( find_out >= i ))
do
file=`head -$i f.out|tail -1`
dir=`dirname $file`
cd $dir
Status=""
if ; then
Status=`cvs -Q status... (3 Replies)
Hi All,
I need to concatenate the values in the array into a variable. Currently the code is :
for (( i=1 ; i <= $minCount ; i++ ))
do
var="${var}""${sample_file}"
done
The output is :
/tmp/1/tmp/2/tmp/3/tmp/4/tmp/5/tmp/6/tmp/7/tmp/8/tmp/9/tmp/10
I need a space between... (1 Reply)
Hi All,
I am comparing two strings inside an if condition if the strings are same then it should go inside the loop else it should execute code given in else part.
But there is a but inside my script
Even if the if condition is true
it is not going inside the loop also it is executing... (4 Replies)
my input file contains thousands of lines like below
234A dept of education
9788 dept of commerce
8677 dept of engineering
How do i add a delimeter ':' after FIRST 4 CHARACTERS in a line
234A:dept of education
9788:dept of commerce
8677:dept of engineering (7 Replies)