printing in certain column based on some result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting printing in certain column based on some result
# 1  
Old 11-13-2008
printing in certain column based on some result

hii every one can anybody help me writing shell script with this,
i have a file ...
amit
arun
vivek

and i want to read something from the user and print next to amit or arun in certain column.. like
amit 23-wall street 2000
arun 34343
vivek 4758

is it possibe with awk command.Smilie
can u please help.
# 2  
Old 11-13-2008
Can you provide more details

awk can format output (as one possible solution)

please show input file and desired output file
# 3  
Old 11-15-2008
Power thanks for reply..

actually i was trying to use a notepad as database..
like ..
name adress phonnum sex
amit 22-wall 1213 male
alena 12-asd 1243 female

actually. i want to take detail from user and place them as shown above..

can u please help.
# 4  
Old 11-15-2008
Play around with something like:

Code:
awk '
BEGIN { printf "Enter your name adress phonenum sex: "
getline name < "-"
s=substr(name,1,match(name," ")-1)
}
$0==s{print name;next}
{print}' file

# 5  
Old 12-11-2008
thanks franklin

can u please elaborate the code ...

thanks
# 6  
Old 12-11-2008
Code:
awk '
BEGIN { printf "Enter your name adress phonenum sex: "
getline name < "-"
s=substr(name,1,match(name," ")-1)
}
$0==s{print name;next}
{print}' file

The code was just an example, left for you to adjust it for your own taste and not as a solution but here we go:


Code:
BEGIN { printf "Enter your name adress phonenum sex: "
getline name < "-"
s=substr(name,1,match(name," ")-1)
}

Ask for a name etc. and substract the name (first word till the first space).

Code:
$0==s{print name;next}

If we match the name print the name , adress etc.

Code:
{print}'

This prints the other lines.

Hope this helps.

Regard
# 7  
Old 12-12-2008
Bug thanks franklin

it has been great help to me

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Add column and multiply its result to all elements of another column

Input file is as follows: 1 | 6 2 | 7 3 | 8 4 | 9 5 | 10 Output reuired (sum of the first column $1*$2) 1 | 6 | 90 2 | 7 | 105 3 | 8 | 120 4 |9 | 135 5 |10 | 150 Please enclose sample input, sample output, and code... (5 Replies)
Discussion started by: Sagar Singh
5 Replies

2. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

3. Shell Programming and Scripting

Awk: Comparing arguments with in line values of file and printing the result

I need to develop a script where I will take two date arguments as parameter date1 and date2 which will in format YYYYMM. Below is the input file say sample.txt. sample.txt will have certain blocks starting with P1. Each block will have a value 118,1:TIMESTAMP. I need to compare the... (7 Replies)
Discussion started by: garvit184
7 Replies

4. Shell Programming and Scripting

Printing rows based on column range

Hello, I have a file with nearly 57K lines. I want to filter the lines based on the range of values in a column. For e.g. print lines whose 3rd filed is >=0.02. Input file: LOC_Os09g32030 LOC_Os02g18880 0.0200037219149773 undirected NA NA LOC_Os03g58630 LOC_Os09g35690 ... (1 Reply)
Discussion started by: Sanchari
1 Replies

5. Shell Programming and Scripting

How to sort grep result based on timestamp?

Hi, Trying to sort grep result based on timestamp of the filename. I have the following result and want to sort them on timestampgrep -i 'ERROR' *log*2013* s_m_xxx_xxx_xxx_xxx_xxxx.log.20130906092431:TRANSF_1_1_1> DBG_21216 Finished transformations for Source Qualifier . Total errors ... (5 Replies)
Discussion started by: bobbygsk
5 Replies

6. Shell Programming and Scripting

Processing result file based on a minimal value

After the great awk solution to my last problem (that saved me days of work) I thought I would try again. I now have a result file that consists of two identifier columns and then columns of data for each sample, with tabs as delimiters (note the sample number can vary depending on the... (8 Replies)
Discussion started by: fozrun
8 Replies

7. Shell Programming and Scripting

printing words based on column match

pls help Input: file1 word1 text1 word2 text2 word3 text3 file2 word1 text11 word3 text13 can u pls help in getting the same output: file1 text1 text2 text3 (1 Reply)
Discussion started by: bha148
1 Replies

8. UNIX for Dummies Questions & Answers

creating a file using the fist column and printing second column

Hello all. I have a problem that I need help solving. I would like to convert the following file: human pool1_12 10e-02 45 67 human pool1_1899 10e-01 45 29 human pool1_1829 10e-01 43 26 horse pool1_343 10e-20 65 191 horse pool1_454 10e-09 44 43... (5 Replies)
Discussion started by: viralnerd
5 Replies

9. Shell Programming and Scripting

Filter the column and print the result based on condition

Hi all This is my output of the some SQL Query TABLESPACE_NAME FILE_NAME TOTALSPACE FREESPACE USEDSPACE Free ------------------------- ------------------------------------------------------- ---------- --------- ---------... (2 Replies)
Discussion started by: jhon
2 Replies

10. Shell Programming and Scripting

awk printing: strange result

Dear all, I am using awk in a bash script to extract a list of x y z coordinates from a file such as: %BEGIN 3D-SPACE COORDINATES 0.2085627338147950 0.2471306816410478 0.2085627338147950 0.1242549179185660 0.2755539793525220 0.4147884486606120 0.2030669560265720 ... (6 Replies)
Discussion started by: pauli
6 Replies
Login or Register to Ask a Question