There's an input file(input.txt) which has the following details :
<Please note the second record has a LEADING WHITESPACE which is VALID>
I am using the following code to read the content of the said file line by line:
This is the output I am getting :
Note : The leading WHITESPACE in the second record is getting removed automatically when the read command
is retrieving the values and assigning it to the variable "p"
HOW CAN I RETAIN THE LEADING WHITESPACE OF A COMMAND OUTPUT ????
IS IT A DEFAULT FEATURE OF UNIX TO REMOVE ALL LEADING/TRAILING WHITESPACE CHARACTERS WHENEVER A COMMAND ASSIGNS ITS OUTPUT TO A VARIABLE
FROM THE STDOUT ??
HOW TO BYPASS IT ??
This same thing happens for the following command also :
It's a feature of the read builtin. It's designed to split on any characters in the IFS special variable, which default to whitespace, but can be set to whatever you want or even nothing.
Also, you should use read's -r switch, to disable backslash escapes, which read otherwise parses too.
The for X in `cat file` loop is an even worse idea, because it doesn't split across lines -- it splits across any whitespace.
Last edited by Corona688; 06-13-2013 at 10:39 AM..
Hello All,
I have a pipe delimited file and below is a sample data how it looks:
CS123 | | || 5897 | QXCYN87876
As stated above, the delimited files contains sometimes only spaces as data fields and sometimes there are extra spaces before/after numeric/character data fields. My requirement... (4 Replies)
Input file:
aaaa bbb dd.
qqq wwww e.
Output file:
a a a a <s> b b b <s> d d .
q q q <s> w w w w <s> e .
Can I use sed to do so in one step? (5 Replies)
HI
I want to remove white spaces from a line
I have a file like
# cat /clsep
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
I need the output like
0
1
2
3
4
.
.
.
15
I feel sed command cannot be used..
I went through the man page of awk command and found (7 Replies)
hello,
i have this string:
variable="1234 /PARAMETER_1:text /PARAMETER_2:othertext"
i tried to do
expr match $variable '.*\(*\)'
but i keep getting expr error
i need to extract the word text...
thank you (4 Replies)
Hi,
Here's my requirement...
There's a SFTP script with batchmode which logs in to the remote site and list all .done files to pick real files (see the following snippet)
echo "-ls $FTP_PATH/*.done" > temp_file
fileNames=`sftp -b temp_file $user@$ip`
isDoneFile=`echo $fileNames |... (2 Replies)
Hi All,
Have a query on finding the lines with at least one whitespace. Have following lines in my file myfile.txt
I
I LOVE
I LOVE FREEDOM
I LOVE FREEDOM
I LOVE FREEDOM AND PEACE
I ran the following query to get the lines with at least 3 words.
grep '\(* +\)\{3,\}' myfile.txt... (6 Replies)
Hi,
i have a file which contains data in fixed length. each row contains data of 10 characters fixed length. The data in the file appears like 4567782882
some times i may recieve dat less than fixed length of 10. in such a case i find nulls appended at the trailing spaces when i do a... (2 Replies)
Hello,
Im trying write a bash sript to search a file and identify any file names that contain a space at the end of them.
I was trying to use the grep command but I can find how I would identify the character I'm looking for.
Any help would be grately appreciated. (2 Replies)
Hello all,
i have a problem.
please help me to remove the white spaces and tabs betweeen line.
i.e.,
file1 contains some text..
text starts_hdsffdsd
sdfsddssdds********
sdfsdsd***********
sdfsdsdfsdsdfsdsds***
****fsd_test_ends
one or 2 blank lines
(* indicates white spaces or tabs)
... (5 Replies)