Grep command functionality - discussed


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Grep command functionality - discussed
# 1  
Old 02-24-2019
Grep command functionality - discussed

what is the following bash command does

Code:
grep `date +%Y-%m-%d --date='1 day ago'` /path/to/file/FILE_PREFIX_\`date +%Y%m%d --date='1 day ago'`.dsv | grep -v 'ERROR' | cut -d "|" -f 2 | sed 's/^0/27/'


Last edited by RudiC; 02-24-2019 at 06:31 AM.. Reason: Removed unnecessary line feed
# 2  
Old 02-24-2019
I'm afraid the title you selected is more than misleading. We're not discussing grep but shell functionality (see below).


There are two steps you can do to elicit how it works from a (compound , complex) command line:

- set the -x (--xtrace) option (or its equivalent) of your shell and execute again. The shell will unveil a lot (not all, alas) of what it does with the parts of the command(s).
- isolate single commands and execute by themselves, like
Code:
$ date +%Y-%m-%d --date='1 day ago'
2019-02-23
$ date +%Y%m%d --date='1 day ago'
20190223

So this would result in a command

Code:
grep 2019-02-23 /path/to/file/FILE_PREFIX_\20190223.dsv

, from which output the lines containing "ERROR" are removed by an "inverted match" when piped through grep -v. Then, the second | delimited field is cut out, and in those, any single leading zero is substituted in the final sed.


Be aware that
a) the "backtick command substitution" `...` is deprecated and outdated and should be replaced by the modern form $(...)-
b) the parameters (not only) to the grep command should be double quoted to avoid problems should the "command substitution" 's result contain spaces et al.

Last edited by RudiC; 02-24-2019 at 06:51 AM..
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Zip -r Functionality

Hi , I've written the following code to zip the big file $dir_temp ="/home/etc/hst zip -r $dir_temp/file_nm.zip $dir_temp/file_nm The zip file has been created . When I try to UNZIP the file with the following command unzip file_nm.zip The file got unzipped but created in the... (3 Replies)
Discussion started by: smile689
3 Replies

2. UNIX for Dummies Questions & Answers

Command Functionality

Hi everyone, today i need that someone help to understand this particular line of command. So you can explain to me step by step, it will be great. ---------- Post updated at 11:53 AM ---------- Previous update was at 11:51 AM ---------- (9 Replies)
Discussion started by: Newer
9 Replies

3. UNIX for Dummies Questions & Answers

Help with the functionality of the last (&/or who) command.

I'm a Bash Newbie, hope you guys can help. n.n Ok, So I need to make a script that will get a list of the Users that are/have logged in (recently). I've been wondering how to get it with either the last or the who command. This Poses a problem, as with who, it ONLY shows the Users... (3 Replies)
Discussion started by: lsteamer
3 Replies

4. Shell Programming and Scripting

Pipe Functionality

Hi, I am trying to emulate the '|' functionality through pipe function call. I am passing the o/p of exec in parent as input to the exec in child. The buf is readin the o/p but the exec in child is not working. Can somebody checkout the code and point where am i going wrong or missing something.... (3 Replies)
Discussion started by: amejoish
3 Replies

5. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

6. UNIX for Dummies Questions & Answers

using functionality in another ksh

i have a function defined in one ksh i want to use the same functionality in another ksh i am using . ../<ksh name> but it is not picking that functionality what i have to do for the same (2 Replies)
Discussion started by: trichyselva
2 Replies

7. UNIX for Advanced & Expert Users

how to exclude the GREP command from GREP

I am doing "ps -f" to see my process. but I get lines that one of it represents the ps command itself. I want to grep it out using -v flag, but than I get another process that belongs to the GREP itself : I would like to exclude # ps -f UID PID PPID C STIME TTY TIME CMD... (2 Replies)
Discussion started by: yamsin789
2 Replies

8. Shell Programming and Scripting

Restartibility Functionality....

Hello, I am trying to write a script that has a option of restarting the script from where it failed. I have to write a script called Batch.sh. This script has to run quite a few sql files as shown below: logcmd.sh -f test1.sql logcmd.sh -f test2.sql logcmd.sh -f test3.sql logcmd.sh -f... (4 Replies)
Discussion started by: rkumar28
4 Replies

9. Shell Programming and Scripting

Sed functionality

I have a few xml files and I want to input say 5 parameters within each file. is it possible to do so with sed? <parameter>A</parameter> <parameter>B</parameter> .... .... And so on. These parameters are meant to go in just inside: <?xml... (2 Replies)
Discussion started by: collern2
2 Replies

10. UNIX for Dummies Questions & Answers

Date functionality

Hi, Could someone help me to get yesterday's date in MMDDYY format. echo `date '+%m%d%y'` is giving me today's date in the above format. Thanks in advance for your help.. Suresh. (1 Reply)
Discussion started by: svannala1
1 Replies
Login or Register to Ask a Question