Visit Our UNIX and Linux User Community

sed within awk statement

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed within awk statement
# 8  
Old 01-10-2018
There is almost never a need to invoke sed from awk (or even to use sed to filter output produced by awk. The awk editing functions can do most of the stuff sed can do and in this case, I find it easier to do it in awk than in sed. Your post #7 seems to ignore the suggestions provided in post #6. Please look at post #6 and let us know whether or not it works for you.
# 9  
Old 01-10-2018
Originally Posted by sagar_1986
. . .
As this input file is received from MySQL query,
. . .
that's why I proposed the MySQL- function DATE_FORMAT. For an SQL server, how about any of these (from this URL)
SELECT convert(varchar, getdate(), 126) - yyyy-mm-ddThh:mm:ss.mmm
                                        - 2008-10-02T10:52:47.513

- SQL create different date styles with t-sql string functions

SELECT replace(convert(varchar, getdate(), 111), /',  ) - yyyy mm dd

This User Gave Thanks to RudiC For This Post:
# 10  
Old 01-10-2018
Thanks sir,Don Cragun

This works perfect for me.

actually when I was replying to post no 5, post 6 came and when I read that I have posted thank you also.
Sorry for inconvenience because of me.

Sir, I am just a beginner in unix world, if you have any document regarding awk command, it would be very much helpful all newbies like me.

Thank you

---------- Post updated at 09:31 AM ---------- Previous update was at 09:21 AM ----------

 SELECT replace(convert(varchar, getdate(), 111), /',  ) - yyyy mm dd

also works perfect

I have one doubt.

if column length is 20 and column variable length is variable say for one digit/ character to n character, then how to auto fit column lengh

 convert(varchar(19),column_name, 112)

here we are fixing length to 19/15 but if column variable are of 4 digit only then how to auto fit column length, is it possible
# 11  
Old 01-10-2018
As with any system-provided utility, the manual pages supplied with your system are always a good place to look to figure out how that utility works. You can start with:
man man

to see how the man command works, and environment variables and options you can set to control what pager is used to view the output it provides. Then move on to:
man awk

to see how awk works on your system.

If the man page whets your appetite and you want to dig a lot deeper, there are hundreds (if not thousands) of examples of awk scripts on this forum and you could try the books:
  • The AWK Programming Language by Aho, Alfred V., Kernighan, Brian W., Weinberger, Peter J. You might note that the initials of the three authors Aho, Weinberger, and Kernighan form the name of this utility; this is no accident--these three authors designed and wrote the utility as well as the book that describes it. Note that this book was written in 1988 which was before some of the current features provided by internationalized regular expressions and some extensions provided by later language maintainers were around, but it still provides a very good overview of how the language works with examples.
  • sed & awk by Dougherty, Dale and Robbins, Arnold. I haven't read this book myself, but others have given it good reviews.

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk statement piped inside sed

Hello folks, I have multiple occurrences of the pattern: ).: where is any digit, in various text context but the pattern is unique as this regex. And I need to turn this decimal fraction into an integer (corresponding percent value: the range of 0-100). What I'm doing is: cat... (1 Reply)
Discussion started by: roussine
1 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

If else statement in sed

Hello Guys, I am new here and this is my first post, hope someone can help me I am writing a script that is supposed to go in 9 different directories and edit a given file in each of the directories. I am using sed to edit the file as sed -i 'line# s/#to be changed/#to be replaced with/... (5 Replies)
Discussion started by: Madiouma Ndiaye
5 Replies

4. Shell Programming and Scripting

Awk/sed problem to write Db insertion statement

Hi There, I am trying to load data from a csv file into a DB during our DB migration phase. I am successfully able export all data into a .csv file but those have to rewritten in terms insert statement which will allow for further population of same data in different DB My exiting csv record... (6 Replies)
Discussion started by: bhaskar_m
6 Replies

5. Shell Programming and Scripting

Use awk/sed/grep with goto statement!

Hi, I have an array with characters and I am looking for specific character in that array and if those specific character not found than I use goto statment which is define somehwhere in the script. My code is: set a = (A B C D E F) @ i = 0 while ($i <= ${#a}) if ($a != "F" || $a != "D")... (3 Replies)
Discussion started by: dixits
3 Replies

6. Shell Programming and Scripting

A complex sed statement

I have following requirement. Say, my text file contains following patterns {2010501005|XXGpvertex|9|0|17|0|{|{30100001|XXparameter_set|@@@@{{30001002|XXparameter|!prototype_path|$AB_COMPONENTS/Sort/Sort.mpc|3|2|Pf$|@{0|}} }}@0|@315000|78500|335000|99000|114000|87000|17|And the Sort|Ab... (8 Replies)
Discussion started by: Shell_Learner
8 Replies

7. Shell Programming and Scripting

sed / grep / for statement performance - please help

I'm searching the most effective way of doing the following task, so if someone can either provide a working solution with sed or one totally different but more effective then what I've got so far then please go ahead! The debugme directory has 3 subdirectorys and each of them has one .txt file... (7 Replies)
Discussion started by: TehOne
7 Replies

8. Shell Programming and Scripting

sed remove statement

I am having some problems with sed, that I am hoping that I can get some assistance with. I am trying to remove two subsets of a string, and cannot figure out how to have it work. Here is an example string: auth_ldap authenticate: user joe authentication failed; URI /svn/ I want to... (4 Replies)
Discussion started by: Guyverix
4 Replies

9. Shell Programming and Scripting

Variables within a sed statement

I am just wondering if it's possible to refer to variables within a sed statement as follows:- cat $file | sed -e 1's/$oldtext/$newtext/' > $file as when I run the script, the variables are not recognised and nothing happens..?? Thanks (5 Replies)
Discussion started by: sirtrancealot
5 Replies

10. Shell Programming and Scripting

if and sed statement

this is my output for my crawler. /about.html /ads/ /advanced_search?hl=en /imghp?hl=en&tab=wi&ie=UTF-8 /intl/en/options/ /language_tools?hl=en /maphp?hl=en&tab=wl&ie=UTF-8... (3 Replies)
Discussion started by: chris1234
3 Replies

Featured Tech Videos