help with script
abc bas
110 jha -a -b -c jhab kam 648 jad -d -e -f if i have this type of data and i just wanna print out 'abc bas' and 'jhab kam'. can someone help! |
Save this data in a file named file1 and try:
Code:
egrep "abc bas|jhab kam" file1 |
I know that one. but the data that I gave has abc bas & jhab kam. but that could be anything.
|
If your data maintains reletively the same format (i.e. 5 lines and a space in between) you can use 'sed' to print every Nth line:
http://linuxcommando.blogspot.com/20...every-nth.html |
Quote:
Code:
egrep "<string1>|<string2>|<string3>..." file1 |
Quote:
Try this: Code:
sed -n '/^[^0-9\-]/p' infile Code:
sed -n '/^[[:alpha:]]/p' infile |
yeah thanks. i already got that one! but how can i number up the lines that i filtered out from this. i sorted them alphabetically. so now i want
1. abc bas 2. jhab kam so that if i ask user to choose a number it will print out the info under that. like choosing 1 it will print out -a -b -c |
Can you tell us what all this is used for? It seems that your questions in post #1 and post #7 are related and part of a larger problem.
It would make it easier for us to understand the problem if you tell us more. - What are you trying to accomplish, - What is the input and how is it used, - Is there any user input, - Any expected output, - ..... BTW: Please put your script/data inside [code] ... [/code] tags it preserves all spacing. If you don't know how: LQ - BB Code List. |
yeah i have a database as i gave example above. i am trying to listing all that info as user want. so at first it will print out those titles and ask user if he/she wants in detail about that by entering number as i said.
if he/she enters 1 then it should print all info under it -a -b -c i am stuck here. |
It seems that you want something like, if user enters 1, then it consider "abc bas" and print the info. that is just below this string (i.e. 4 lines below "abc bas"), and same if user enters 2, it considers "jhab kam"... and so on.
It is ok for a small file. But for a large database, you will need to assign a unique number to each user!! So, will your script user be able to remember number associated with the username entry that he/she's going to serach (I am assuming huge number of username entries in database)? I don't think so. Instead of using numbers, you should better direct take username of the user whose database entries he/she's seaching, as input from him/her. Following may be helpful: Code:
#!/bin/bash Code:
<username> |
yeah that can work but the question that i have it says use numbers. its like user to choose a username by entering the number, or to quit by entering a q
|
Quote:
I feel that you're confused!! So as I said above, if pb has not been solved yet, then clearly mention everything, including sample db file, sample output you want, and your purpose of using numbers instead of usernames. Also pls use correct grammer & punctuation in your post, so it can be easily understandable. |
Quote:
|
Please explain the difference between this question and the one you posted earlier here?
|
i filtered usernames out but now i wanna ask user about who's info he/she wanna see.
like , username1 username2 but dont know how can i key those names to numbers. so if username enters 1 it wil give info on 1. |
All times are GMT -5. The time now is 10:32 AM. |