Output to file print as single line, not separate line
example of problem:
when I echo "$e" >> /home/cogiz/file.txt
result prints to file as:
I need it to save to file as this:
I know it's probably something really simple but any help would be greatly appreciated.
Thank You.
Cogiz
Last edited by rbatte1; 11-16-2016 at 06:50 AM..
Reason: Added CODE tags
example of problem:
when I echo "$e" >> /home/cogiz/file.txt
result prints to file as:
AA
BB
CC
I need it to save to file as this:
AA BB CC
I know it's probably something really simple but any help would be greatly appreciated.
Thank You.
Cogiz
Hello cogiz,
One more easy way is there to do so, you could remove " in echo and do like echo $e it will print output as AA B CC, because " actually reads characters with their special meaning so values will not loose their new line but when we do simple echo they will(new line in current scenario) loose their special meaning, so in your case you could take advantage of this feature.
One more easy way is there to do so, you could remove " in echo and do like echo $e it will print output as AA B CC, because " actually reads characters with their special meaning so values will not loose their new line but when we do simple echo they will(new line in current scenario) loose their special meaning, so in your case you could take advantage of this feature.
Thanks,
R. Singh
This is not true. It could be possible that your echo is aliased to echo -n(or may be the flavour of echo in your OS behaves this way? Not sure)
Assuming you have a loop of some sort around your output statement, you could do something like this:-
It's up to you where you want to set the redirection to append to the file. If you want to overwrite the file each time, you can perform a file open with:-
I have written the printf with two arguments in case $var contains spurious data that could cause printf to do something unexpected. Some people find this annoying but it protects you somewhat from potentially damaging input.
result prints to file as:
I need it to save to file as this:
I know it's probably something really simple but any help would be greatly appreciated.
Thank You.
Cogiz
Hi cogiz,
To get the results shown above (i.e., changing <newline>s between words in the input to <space>s between words in the output, but keeping a trailing <newline> at the end of the output), e had to be set with something logically equivalent to:
e="AA
BB
CC"
Note that this variable contains two embedded <newline>s. Therefore, the suggestions provided by rdrtx1 and balajesuri will NOT work. The quoted argument ("$e") keeps those embedded <newline> visible in the output from those suggestions. Note also that these non-working suggestions are a direct result of your failure to use CODE tags to make clear what input you had and what output you wanted.
The suggestion RavinderSingh13 provided should do exactly what you requested. The unquote argument ($e) passed to echo causes the shell to split the expansion of that variable into three operands, each of which will be printed as a string with a <space> separating the fields in the output and a single <newline> will be printed at the end.
This User Gave Thanks to Don Cragun For This Post:
I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
performing this code to read from file and print each character in separate line
works well with ASCII encoded text
void
preprocess_file (FILE *fp)
{
int cc;
for (;;)
{ cc = getc (fp);
if (cc == EOF)
break;
printf ("%c\n", cc);
}
}
int
main(int... (1 Reply)
I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched,
finally need to print these three values in a single line.
Sample Log:
2013/06/11 14:29:04 <0999> (725102) Processing batch 02_1231324
2013/06/11... (4 Replies)
Hi all,
I have a single line output like below
echo $ips
10.26.208.28 10.26.208.26 10.26.208.27
want to convert above single line output as below format. Pls advice how to do ?
10.26.208.28
10.26.208.26
10.26.208.27
Regards
Kannan (6 Replies)
Hi,
My Oracle query is returing below o/p
----------------------------------------------------------
Ins trnas value
a lkp1 x
a lkp1 y
b lkp1 a
b lkp2 x
b lkp2 y ... (7 Replies)
I have a large 3479 line .csv file, the content of which looks likes this:
1;0;177;170;Guadeloupe;x
2;127;171;179;Antigua and Barbuda;x
3;170;144;2;Umpqua;x
4;170;126;162;Coos Bay;x
...
1205;46;2;244;Unmak Island;x
1206;47;2;248;Yunaska Island;x
1207;0;2;240;north sea;x... (5 Replies)
Hello UNIX experts,
I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines.
e.g. The input Files are one.txt, two.txt, three.txt, four.txt
The cat of four... (1 Reply)
Hi,
Please suggest, how to get the output of below script in single line, its giving me in different lines
______________________
#!/bin/ksh
export Path="/abc/def/ghi";
Home="/home/psingh/prat";
cd $Path;
find $Path -name "*.C#*" -newer "abc.C#1234" -print > $Home
cat $Home | while... (1 Reply)
hey gents,
I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Hi
I have a file with contents like
china
india
france
japan
italy
germany
.
.
.
.
etc....
I want the output as
china|india|france|japan|italy|germany|.|.|. (3 Replies)