Unable to print "|" in echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to print "|" in echo
# 1  
Old 07-01-2018
Unable to print "|" in echo

I have a small script that works well but when I am putting pipes at the end of the echo command, output is getting weird.
My script it below:
Code:
sed '1d' CONTROL_TOTALS_*.txt | while read eachline
do
tblnm=`echo $eachline | cut -d'_' -f3`
if [ $tblnm == 'PROV' ]
then stg_tblnm='PROVIDER_CONTRACT'
elif [ $tblnm == 'MEMBER' ]
then stg_tblnm='MEMBER'
elif [ $tblnm == 'PROVIDER' ]
then stg_tblnm='PROVIDER'
elif [ $tblnm == 'VENDOR' ]
then stg_tblnm='VENDOR'
fi
file=`echo $eachline | cut -d'.' -f1`
filenm=`echo "${file}*.zip"`
filedt=`ls -lrt $filenm | awk '{print $7}'`
if [ ${#filedt} -eq 1 ] 
then 
filedt1=`echo "0${filedt}"`
else
filedt1=`echo "$filedt"`
fi
filemon=`ls -lrt $filenm | awk '{print $6}' | tr '[:lower:]' '[:upper:]'`
filercvddt=`echo "${filedt1}-${filemon}-2018"`
rec_count=`echo $eachline | cut -d'|' -f2`
inc_filenm=`echo $eachline | cut -d'|' -f1`
echo "$stg_tblnm||$ctrl_filenm|$inc_filenm|$filercvddt|$rec_count|||"
done


Output am getting from above script is:
Code:
|||BER||CONTROL_TOTALS_2018063072839.zip|MEMBER_2018063072729.txt|30-JUN-2018|2545104
|||VIDER||CONTROL_TOTALS_2018063072839.zip|PROVIDER_2018063064018.txt|30-JUN-2018|19086
|||VIDER_CONTRACT||CONTROL_TOTALS_2018063072839.zip|PROV_CONTRACT_2018063064256.txt|30-JUN-2018|1287604
|||DOR||CONTROL_TOTALS_2018063072839.zip|VENDOR_2018063063830.txt|30-JUN-2018|35

Expected output is something like this:
Code:
MEMBER||CONTROL_TOTALS_2018063072839.zip|MEMBER_2018063072729.txt|30-JUN-2018|2545104|||
PROVIDER||CONTROL_TOTALS_2018063072839.zip|PROVIDER_2018063064018.txt|30-JUN-2018|19086|||
PROVIDER_CONTRACT||CONTROL_TOTALS_2018063072839.zip|PROV_CONTRACT_2018063064256.txt|30-JUN-2018|1287604|||
VENDOR||CONTROL_TOTALS_2018063072839.zip|VENDOR_2018063063830.txt|30-JUN-2018|35|||

If I am removing the last three pipes from the echo then all the variables are getting printed out.
Code:
echo "$stg_tblnm||$ctrl_filenm|$inc_filenm|$filercvddt|$rec_count"

Output in that case is something like this:
Code:
MEMBER||CONTROL_TOTALS_2018063072839.zip|MEMBER_2018063072729.txt|30-JUN-2018|2545104
PROVIDER||CONTROL_TOTALS_2018063072839.zip|PROVIDER_2018063064018.txt|30-JUN-2018|19086
PROVIDER_CONTRACT||CONTROL_TOTALS_2018063072839.zip|PROV_CONTRACT_2018063064256.txt|30-JUN-2018|1287604
VENDOR||CONTROL_TOTALS_2018063072839.zip|VENDOR_2018063063830.txt|30-JUN-2018|35

What am I missing is echo?
Please assist!
Thanks in advance.
# 2  
Old 07-01-2018
On first glance I'd bet there are DOS line terminators (<carriage return>, <CR>, \r, 0x0D, ^M) in the original file. You could remove those in the upfront sed command (s/\r//).
# 3  
Old 07-01-2018
Hi RudiC
Thanks for commenting. I used "dos2unix" utility on the CONTROL_TOTALS_*.txt file before I used sed on it.
Is that something that's not going to solve the control-m and CR return problem.
# 4  
Old 07-01-2018
Pls. post (a small but representative part of) the output of od -tx1c CONTROL_TOTALS_*.txt
# 5  
Old 07-01-2018
Here is the output:

Code:
0000000  52  65  70  6f  72  74  20  4e  61  6d  65  7c  52  65  63  6f
           R   e   p   o   r   t       N   a   m   e   |   R   e   c   o
0000260  4d  5f  43  50  49  5f  56  45  4e  44  4f  52  5f  49  4e  43
           E   _   C   P   I   _   V   E   N   D   O   R   _   I   N   C
0000300  5f  32  30  31  38  30  36  33  30  36  33  38  33  30  2e  74
           _   2   0   1   8   0   6   3   0   6   3   8   3   0   .   t
0000320  78  74  7c  33  35  0a
           x   t   |   3   5  \n
0000326



One thing to note, file when opened in notepad doesnt show any record separator. But, when using cat or other text editors like Notepad++ and Ultraedit file opens just fine with line breaks.

Last edited by svks1985; 07-01-2018 at 03:57 AM..
# 6  
Old 07-01-2018
Pls post a contiguous section including at least one line break. Are you sure above hexdump is from the input file?
# 7  
Old 07-01-2018
Here is the complete output:

Code:
0000000  52  65  70  6f  72  74  20  4e  61  6d  65  7c  52  65  63  6f
           R   e   p   o   r   t       N   a   m   e   |   R   e   c   o
0000020  72  64  20  43  6f  75  6e  74  73  0a  4d  45  4d  42  45  52
           r   d       C   o   u   n   t   s  \n   M   E   M   B   E   R
0000040  5f  49  4e  43  5f  32  30  31  38  30  36  33  30  37  32  30
           _   I   N   C   _   2   0   1   8   0   6   3   0   7   2   0
0000060  30  32  2e  74  78  74  7c  32  35  34  31  39  32  39  0a  50
           0   2   .   t   x   t   |   2   5   4   1   9   2   9  \n   P
0000100  52  4f  56  49  44  45  52  5f  49  4e  43  5f  32  30  31  38
           R   O   V   I   D   E   R   _   I   N   C   _   2   0   1   8
0000120  30  36  33  30  36  33  39  32  34  2e  74  78  74  7c  35  38
           0   6   3   0   6   3   9   2   4   .   t   x   t   |   5   8
0000140  36  33  0a  50  52  4f  56  5f  43  4f  4e  54  52  41  43  54
           6   3  \n   P   R   O   V   _   C   O   N   T   R   A   C   T
0000160  5f  49  4e  43  5f  32  30  31  38  30  36  33  30  36  34  33
           _   I   N   C   _   2   0   1   8   0   6   3   0   6   4   3
0000200  30  30  2e  74  78  74  7c  35  32  35  32  39  36  0a  56  45
           0   0   .   t   x   t   |   5   2   5   2   9   6  \n   V   E
0000220  4e  44  4f  52  5f  49  4e  43  5f  32  30  31  38  30  36  33
           N   D   O   R   _   I   N   C   _   2   0   1   8   0   6   3
0000240  30  36  33  36  30  34  2e  74  78  74  7c  31  30  32  0a
           0   6   3   6   0   4   .   t   x   t   |   1   0   2  \n
0000257

---------- Post updated at 10:47 AM ---------- Previous update was at 09:40 AM ----------

Seems like I found the solution. Problem lies with the control file. It has \n (LF) between the lines. It should have \r\n (CR + LF).
This would work to convert the file:
Code:
awk '{printf "%s\r\n", $0}' CONTROL_FILE.txt

I would let you know how that goes.
Thanks RudiC for showing me the torch light :-)

---------- Post updated at 01:15 PM ---------- Previous update was at 10:47 AM ----------

Fixed the control file and still getting the same issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

3. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

4. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

9. SuSE

VMDB Failure" followed by "Unable to open snapshot file"

keep getting an error when I try to revert to a snapshot: "VMDB Failure" followed by "Unable to open snapshot file" Im using vmware server 1.0.4, host OS is windows xp and guest OS is SLES. Is there anything I can do to recover the snapshot or am I in trouble!?!?! (0 Replies)
Discussion started by: s_linux
0 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question