Sponsored Content
Full Discussion: Unable to print "|" in echo
Top Forums Shell Programming and Scripting Unable to print "|" in echo Post 303019508 by svks1985 on Sunday 1st of July 2018 01:13:46 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
FUNZIP(1)						      General Commands Manual							 FUNZIP(1)

NAME
funzip - filter for extracting from a ZIP archive in a pipe SYNOPSIS
funzip [-password] [input[.zip|.gz]] ARGUMENTS
[-password] Optional password to be used if ZIP archive is encrypted. Decryption may not be supported at some sites. See DESCRIPTION for more details. [input[.zip|.gz]] Optional input archive file specification. See DESCRIPTION for details. DESCRIPTION
funzip without a file argument acts as a filter; that is, it assumes that a ZIP archive (or a gzip'd(1) file) is being piped into standard input, and it extracts the first member from the archive to stdout. When stdin comes from a tty device, funzip assumes that this cannot be a stream of (binary) compressed data and shows a short help text, instead. If there is a file argument, then input is read from the speci- fied file instead of from stdin. A password for encrypted zip files can be specified on the command line (preceding the file name, if any) by prefixing the password with a dash. Note that this constitutes a security risk on many systems; currently running processes are often visible via simple commands (e.g., ps(1) under Unix), and command-line histories can be read. If the first entry of the zip file is encrypted and no password is specified on the command line, then the user is prompted for a password and the password is not echoed on the console. Given the limitation on single-member extraction, funzip is most useful in conjunction with a secondary archiver program such as tar(1). The following section includes an example illustrating this usage in the case of disk backups to tape. EXAMPLES
To use funzip to extract the first member file of the archive test.zip and to pipe it into more(1): funzip test.zip | more To use funzip to test the first member file of test.zip (any errors will be reported on standard error): funzip test.zip > /dev/null To use zip and funzip in place of compress(1) and zcat(1) (or gzip(1) and gzcat(1)) for tape backups: tar cf - . | zip -7 | dd of=/dev/nrst0 obs=8k dd if=/dev/nrst0 ibs=8k | funzip | tar xf - (where, for example, nrst0 is a SCSI tape drive). BUGS
When piping an encrypted file into more and allowing funzip to prompt for password, the terminal may sometimes be reset to a non-echo mode. This is apparently due to a race condition between the two programs; funzip changes the terminal mode to non-echo before more reads its state, and more then ``restores'' the terminal to this mode before exiting. To recover, run funzip on the same file but redirect to /dev/null rather than piping into more; after prompting again for the password, funzip will reset the terminal properly. There is presently no way to extract any member but the first from a ZIP archive. This would be useful in the case where a ZIP archive is included within another archive. In the case where the first member is a directory, funzip simply creates the directory and exits. The functionality of funzip should be incorporated into unzip itself (future release). SEE ALSO
gzip(1), unzip(1), unzipsfx(1), zip(1), zipcloak(1), zipinfo(1), zipnote(1), zipsplit(1) URL
The Info-ZIP home page is currently at http://www.info-zip.org/pub/infozip/ or ftp://ftp.info-zip.org/pub/infozip/ . AUTHOR
Mark Adler (Info-ZIP) Info-ZIP 20 April 2009 (v3.95) FUNZIP(1)
All times are GMT -4. The time now is 07:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy