Sponsored Content
Top Forums Shell Programming and Scripting Help required to Print Single quote into a file Post 302978885 by RavinderSingh13 on Friday 5th of August 2016 06:51:15 AM
Old 08-05-2016
Quote:
Originally Posted by imrandec85
RavinderSingh13, I was facing some other issue using commands provided. Problem: The cursor is moving to next line [>] expecting some other commands i guess, anyways thank you for the response.
Hello imrandec85,

I have used following one-liner solution and it worked for me.
Code:
awk -vs1="'" -vs2="\""  -vs3="\\" 'BEGIN{
                                          print "awk -vs1=" s2 s1 s2 " -vs2=" \
                                          s2 s3 s2 s2 OFS s1 \
                                          "BEGIN{print " s2 "#!/bin/sh" s2 " ORS " s2 \
                                          " for FILE in $*"  \
                                          s2 "ORS " s2 "do" s2 "ORS " s2 "awk  " s2 " s1 " \
                                          s2 "{$0 = FILENAME " s2 "s2 " s2 "|" s2 " s2 " s2 "$0; print}"  \
                                          s2 "s1 " s2 " $FILE" s2 " ORS " s2 "done" s2 ">> " s2 "append_flname.sh"  \
                                          s2 "}" s1 " | sh" ORS "chmod 755 append_flname.sh" ORS "./append_flname.sh  Input_file1  Input_fil2"
                                         }
                                   '  | sh

EDIT: Checked non-one liner in my previous post and both solutions are working as expected as follows.
Code:
awk -vs1="'" -vs2="\""  -vs3="\\" 'BEGIN{print "awk -vs1=" s2 s1 s2 " -vs2=" s2 s3 s2 s2 OFS s1 "BEGIN{print " s2 "#!/bin/sh" s2 " ORS " s2 " for FILE in $*" s2 "ORS " s2 "do" s2 "ORS " s2 "awk  " s2 " s1 " s2 "{$0 = FILENAME " s2 "s2 " s2 "|" s2 " s2 " s2 "$0; print}"  s2 "s1 " s2 " $FILE" s2 " ORS " s2 "done" s2 ">> " s2 "append_flname.sh" s2 "}" s1 " | sh" ORS "chmod 755 append_flname.sh" ORS "./append_flname.sh Input_file1  Input_file2"}' | sh

Output came as follows.
Code:
Input_file1|                      03/08/2016 09:40-09:45            4       0.0
Input_file1|*********                        ------------ ---------
Input_file2|test|chumma_test
Input_file2|test|chumma_test11

Thanks,
R. Singh

Last edited by RavinderSingh13; 08-05-2016 at 08:01 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

single quote

Hi I have a shell script with many lines as below: comment on column dcases.proj_seq_num is dcases_1sq; .... .... I want the above script to be as below: comment on column dcases.proj_seq_num is 'dcases_1sq'; I want to have single quotes like that as above for the entire shell... (2 Replies)
Discussion started by: dreams5617
2 Replies

2. UNIX for Dummies Questions & Answers

how to print single quote in awk

Hi all, It is a very stupid problem but I am not able to find a solution to it. I am using awk to get a column from a file and I want to get the output field in between single quotes. For example, Input.txt 123 abc 321 ddff 433 dfg ........ I want output file to be as ... (6 Replies)
Discussion started by: gauravgoel
6 Replies

3. Shell Programming and Scripting

want to print single quote using awk

i want to print ' symbol using awk i tried: awk '{print " ' "}' awk '{print "\' "}' both not work please help me. (2 Replies)
Discussion started by: RahulJoshi
2 Replies

4. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

5. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

6. Shell Programming and Scripting

awk print: howto single quote not interpreted!?

cat a | awk -F";" '{print "update db set column=' "$2" ' where column1=\""$1"\";"}' > ip-add.sql Hi! I'm a new user! i need to use single quote in the double quotes print string The apex between che "$2" should not be interpreted, but....how?! I'm trying to use \ but don't work correctly! ... (4 Replies)
Discussion started by: Re DeL SiLeNziO
4 Replies

7. Shell Programming and Scripting

How do you print a single quote character in AWK

How do you print out a single quote character in AWK? Using the escape character does not seem to work. {printf "%1$s %2$s%3$s%2$s\n" , "INCLUDE", " \' ", "THIS" } does not work. Any suggestions? (6 Replies)
Discussion started by: cold_Que
6 Replies

8. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

9. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

10. Shell Programming and Scripting

Single quote _error_.

Hi all... (This is Don's domain.) I have come across an anomaly in sh and dash compared to bash. It involves echoing a character set to a file in sh and dash compared to bash. It is probably easier to show the code and results first. #!/usr/local/bin/dash #!/bin/sh #!/bin/bash echo... (4 Replies)
Discussion started by: wisecracker
4 Replies
All times are GMT -4. The time now is 12:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy