Print the whole line which contains the result of the command cut


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print the whole line which contains the result of the command cut
# 1  
Old 02-02-2012
Print the whole line which contains the result of the command cut

Hey everyone

I have a file 'agenda' which contains:
Code:
Object          Day          Month           Year
Birthday         09             02             2012

i want to extract from a script the line which contains the day the user typed.
for example if he type 09 the line is showed using the commande cut

using awk in terminal its working but with cut it isnt working it returns me just the number i typed

i did:
Code:
cat monagenda | cut -d"            " -f2 | grep 09
cat monagenda | cut -d"            " -f2 | sed -ne '/09/p'

both return just 09 otherwise i want to show the whole line Smilie
thank you and sorry for my bad english.

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 02-02-2012 at 07:34 AM..
# 2  
Old 02-02-2012
Code:
grep "09" monagenda

# 3  
Old 02-02-2012
Thank you for your answer but im wondering if its possible to use the Cut command.

thank you again for yout interest Smilie
# 4  
Old 02-02-2012
Code:
 
$ input=09
$ echo $input
09
 
$ cat test.txt
Object          Day          Month           Year
Birthday         09             02             2012
Birthday         02             02             2012


$ nawk -v inp="$input" 'index($2,inp)>0' test.txt
Birthday         09             02             2012

---------- Post updated at 05:19 PM ---------- Previous update was at 05:17 PM ----------

Code:
$ tr -s " " < test.txt | cut -d" " -f2
Day
09

# 5  
Old 02-02-2012
Thank you it worked. never tried this one.

thank you again and have a nice day Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a multi-line shell command output and execute logic based on result

The following is a multi-line shell command example: $cargo build Compiling prawn v0.1.0 (/Users/ag/rust/prawn) error: failed to resolve: could not find `setup_panix` in `human_panic` --> src/main.rs:14:22 | 14 | human_panic::setup_panix!(); | ... (2 Replies)
Discussion started by: yogi
2 Replies

2. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies

3. UNIX for Beginners Questions & Answers

How do I use the cut command to only print the directories?

How would I use ls -l | cut to just print the directories part from the ls -l command? (9 Replies)
Discussion started by: steezuschrist96
9 Replies

4. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

5. UNIX for Dummies Questions & Answers

Cut command doesn't remove (^C) character from only first line

I have a file which has first 2 junk characters(X^C) at beginning of each line in file. When i run cut -c 2- filename it removes junk characters from all lines except on first line it keeps one junk character control C(^C). Not sure why it is not removing only from first line. (2 Replies)
Discussion started by: later_troy
2 Replies

6. Emergency UNIX and Linux Support

Cut | command line args

Hi, Can you please hint me how to achieve the below? Input: $./script.sh start 1 2 Internally inside the script i want to set a single variable with $2 and $3 value? Output: CMD=$1 ARGS=$2 $3 --VInodh (10 Replies)
Discussion started by: vino_hymi
10 Replies

7. Shell Programming and Scripting

uniform and same result whois command line

I am looking for a free whois lookup tool or some "scripting help" that will give uniform result for whois lookup from the linux command line. Currently: whois of a .co.nz domain results nameserver as follows. ns_name_01: ns1.domain.co.nz ns_name_02: ns2.domain.co.nz While that of a .net... (5 Replies)
Discussion started by: anilcliff
5 Replies

8. Shell Programming and Scripting

cut command issue from a line of text

Hi, I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut... (5 Replies)
Discussion started by: asutoshch
5 Replies

9. Programming

Help: Run Java Command Line, Send Result to PHP?

EDIT: Sorry for the post, my good friend Google helped me out after some good searching! (0 Replies)
Discussion started by: tguillea
0 Replies

10. Shell Programming and Scripting

**HELP** need to split this line faster than cut-command

Hi, A datafile containing lines such as below needs to be split: 500000000000932491683600000000000000000000000000016800000GS0000000000932491683600*HOME I need to get the 2-5, 11-20, and 35-40 characters and I can do it via cut command. cut -c 2-5 file > temp1.txt cut -c 11-20 file >... (9 Replies)
Discussion started by: daytripper1021
9 Replies
Login or Register to Ask a Question