Display a specific words from a multiple lines


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Display a specific words from a multiple lines
# 1  
Old 06-02-2011
Display a specific words from a multiple lines

well, i am so not familiar with this kind of things but i am gonna explain extactly what i am looking for so hopfully someone can figure it out Smilie

i have a command that shows memory usage besides the process name, for example(the command output):

500 kb process_1
600 kb process_2
700 kb process_3
800 kb process_4
700 kb process_5
100 kb process_6

i want to write a script which suppose to show the processes with the desired parameter

for example if the user want the processes with memory usage of 600kb and greater the user should pass 600 as a parameter and this script suppose to show the following :

process_2
process_3
process_4
process_5

the problem is i am so bad with scripting, and i really need this as fast as possible Smilie i would really appreciate if someone could help

Last edited by Portabello; 06-02-2011 at 06:11 PM..
# 2  
Old 06-02-2011
Try:
Code:
#!/bin/bash
echo "Enter value: "
read x
your_command | awk -vx=$x '$1>=x'

# 3  
Old 06-02-2011
Code:
#!/bin/bash 
echo "Enter value: " 
read x 
your_command | awk -vx=$x '$1>=x{print $NF}'

# 4  
Old 06-02-2011
Thanks alot guys Smilie, i am going to try it tomorrow at work =)))))
# 5  
Old 06-03-2011
i am trying to save the output of the command as a temprory output so i could use it within the script

i have already tried this one but it couldn't work

Code:
TEMPDIR=/dir1/dir2
 
final_command> $TEMPDIR/$TEMPFILE
 
rm $TEMPDIR/$TEMPFILE*

it keeps saying "cannot write to a directory"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Display multiple words into a single td tag

awk 'BEGIN{print "<table>"} {print "<tr>"; for ( i=1;i<NF;i++) print " <td>" $I "</td>"; print "</tr>"} END{print " </table>"}' <file name > (6 Replies)
Discussion started by: Himanshu1
6 Replies

2. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

3. Shell Programming and Scripting

Display specific lines content from the file

Hell, I want to grep certain word from file and display above 2 lines and after two lines. Here is the content of sample file. Mar 14, 2013 12:56:59 AM Agent.Agent SendTo INFO: Connection to server:7041 - Credential Transmit Successesful Mar 14, 2013 8:54:21 AM cgent SendTo WARNING:... (7 Replies)
Discussion started by: balareddy
7 Replies

4. Shell Programming and Scripting

how to print specific lines or words

Hi, Please have a look on below records. STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: The value of the row is: EMPLID = 220677 COMPANY = 919 BALANCE_ID = 0 BALANCE_YEAR = 2012 STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: ORA-00001: unique constraint (SYSADM.PS_TAX_BALANCE) violated ... (4 Replies)
Discussion started by: Sachin Lakka
4 Replies

5. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

6. Shell Programming and Scripting

Bringing together words from multiple lines

I want to get a file together that lists router name and IP address of an interface together like so... SOMERTR1A 10.10.10.20 SOMERTR1B 10.10.10.30 OTHRRTR1A 192.168.1.120 The file I'm trying to extract the text from looks like the below: SOMERTR1A#show run int Lo0 | i add ... (5 Replies)
Discussion started by: branrobi
5 Replies

7. Shell Programming and Scripting

Keep lines with specific words up in an order

I hava a file with following data: number|CREDIT_ID|NULL date|SYS_CREATION_DATE|NULL varchar2|GGS_COMMIT_CHAR|NULL varchar2|GGS_OP_TYPE|NULL number|GGS_SCN|NULL| number|GGS_LOG_SEQ|NULL number|GGS_LOG_POS|NULL number|GGS_ORACREC_SCN|NULL varchar2|BATCH_ID|NULL char|GGS_IMAGE_TYPE|NULL ... (6 Replies)
Discussion started by: kolesunil
6 Replies

8. UNIX for Dummies Questions & Answers

how to display specific lines of a specific file

are there any basic commands that can display lines 99 - 101 of the /etc/passwd file? I'm thinking use of head and tail, but I forget what numbers to use and where to put /etc/passwd in the command. (2 Replies)
Discussion started by: raidkridley
2 Replies

9. Shell Programming and Scripting

Ignore some lines with specific words from file comparison

Hi all, I need help in doing this scenario. I have two files with multiple lines. I want to compare these two files but ignoring the lines which have words like Tran, Loc, Addr, Charge. Also if i have a word Credit in line, i want to tokenize (i.e string after character " ... (2 Replies)
Discussion started by: jakSun8
2 Replies

10. UNIX for Dummies Questions & Answers

Display multiple output lines

All, I have a file ABC.TXT which has two records: 12345 19.93 34.94 12345 94.84 10.48 If do the following command and grep '12345' ABC.TXT >> test1.txt If I look at the output of test1.txt I appears as follows: 12345 19.93 34.94 12345 94.84 10.48 I... (5 Replies)
Discussion started by: kingofprussia
5 Replies
Login or Register to Ask a Question