Howto use grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Howto use grep command
# 1  
Old 07-26-2012
Howto use grep command

Hi all ,
i am having a table which contains start date and end date
for ex ..
startdate enddate
12/03/2011 12/04/2012
11/03/2011 20/05/2011
11/04/2011 28/07/2011

how to grep startdate = 12/03/2011
enddate = 28/07/2011

i need output :-
startdate:12/03/2012
enddate:28/07/2011

Any body know the solutoins help me........
# 2  
Old 07-26-2012
Code:
awk '$1 == "12/03/2011" || $2 == "28/07/2011" {print}' file

# 3  
Old 07-26-2012
Code:
head -1 file | awk '{ print "startdate="$1 }' 
tail -1 file | awk '{ print "enddate="$NF }'


Last edited by pamu; 07-27-2012 at 04:23 AM..
# 4  
Old 07-26-2012
Code:
awk 'NR==1{print "startdate:",$1}END{print "enddate:",$2}' infile

# 5  
Old 07-26-2012
Quote:
Originally Posted by pamu
Code:
cat file | head -1 | awk '{ print "startdate="$1 }' 
cat file | tail -1 | awk '{ print "enddate="$NF }'

Useless Use of Cat
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep command giving different result for different users for same command

Hello, I am running below command as root user #nodetool cfstats tests | grep "Memtable switch count" Memtable switch count: 12 Where as when I try to run same command as another user it gives different result. #su -l zabbix -s /bin/bash -c "nodetool cfstats tests | grep "Memtable switch... (10 Replies)
Discussion started by: Pushpraj
10 Replies

2. Shell Programming and Scripting

Howto get only filename from find command in Linux?

Hi every body! I would like to get only filename in the result of find command in Linux but I don't know howto. Tks so much for your helps. (5 Replies)
Discussion started by: nguyendu0102
5 Replies

3. Shell Programming and Scripting

Help with using grep command with copy command

Hi, im taking an entry Unix class, and as part of my lab assignment I have to copy all files in the /home/david/lab3 directory that have the file extension .save to your lab3/temp directory. I'm having trouble getting the grep to do anything worth while I've been trying to do: cp... (6 Replies)
Discussion started by: Critical jeff
6 Replies

4. Shell Programming and Scripting

howto substitute word in vi command mode

Hi I'm trying to substitute word "January" with word "March" in my script but in certain lines only. I have couple words containing pattern that I want to substitute e.g. - log.January.1.array - log_January_1_array_1 - log.January.1.array - log_January_1_array_11 Trying to do cmd below... (9 Replies)
Discussion started by: presul
9 Replies

5. Solaris

Looking for CIFS howto

I just skimmed through the Administration Guide about LDAP and CIFS. Well that's a whole lot of text. Does someone know a tutorial/introduction with some steps to make? TIA (14 Replies)
Discussion started by: PatrickBaer
14 Replies

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

7. Shell Programming and Scripting

HowTo: reg expr doing grep "timestamp>$DesiredTime" logfile ?

I know I asked a similar question but I want to know if there is a regular expression existing that with a korn shell cmd, finds any timestamp data records in a file where it is greater then a timestamp in a shell variable ? something like : grep all records where it has a timestamp >... (5 Replies)
Discussion started by: Browser_ice
5 Replies

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

9. UNIX for Dummies Questions & Answers

system () howto ??

How do you write a command to : A text line to a file in ./DATA1/archive.log using system () in awk TodayDate Time scriptname.ksh filename.dat system(echo `date '+%D %T` scriptname.ksh >> ./DATA/archive.log) --> syntax error +%D Thanks for your help (0 Replies)
Discussion started by: britney
0 Replies

10. UNIX for Dummies Questions & Answers

howto

Dear All , Kindly I have some questions , I need hints or answers please . I have sparc4 , sun solaries 7 , mail server . i have about 5000 users , with no login shell , or home directories for the users . they only have mail boxes in /var/mail dir . now , I do not have any type of... (6 Replies)
Discussion started by: tamemi
6 Replies
Login or Register to Ask a Question