awk copy first column in new lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk copy first column in new lines
# 1  
Old 02-04-2018
awk copy first column in new lines

Hi all
i have table like this


input
Code:
001_1_174    j                         474536         482492          
mo[g/n                    482492         504062          
'er/                      504062         517352          
ruze                      517352         529562                 
001_1_175    j                         960192         966656          
.ire                      966656         984416          
.uf/[                     984416         1006166   
.
.

i want copy number of first line to other line until another number and do this for next number

out
Code:
001_1_174    j                         474536         482492          
001_1_174 mo[g/n                    482492         504062          
001_1_174 'er/                      504062         517352          
001_1_174 ruze                      517352         529562                 
001_1_175    j                         960192         966656          
001_1_175 .ire                      966656         984416          
001_1_175 .uf/[                     984416         1006166   
.
.

may explain your codes please?




thank all

Last edited by RudiC; 02-05-2018 at 05:13 AM.. Reason: Removed unnecessary code tags.
# 2  
Old 02-04-2018
First let us start with the standard questions that should be answered in your first post in any technical thread:
  1. What operating system are you using?
  2. What shell are you using?
  3. What have you tried to solve this problem on your own?
Then we can move on to details specific to this thread:
  1. Numbers do not contain underscore characters. Why do you call 001_1_174 a number?
  2. What criteria are to be used to decide if the first column in an input line is numeric?
  3. Is the criteria that the second field on a line is the string "j"?
  4. Can your numbers have leading plus or minus signs?
  5. Can your numbers have decimal points? If so, what is your decimal point character?
  6. Can your numbers have thousands separators?
  7. Can your numbers have a leading or trailing currency symbol?
  8. Where is this table that you have?
  9. What is the format of this table?
If you want us to do your work for you, you can at least give us the details needed to figure out what must be done. Note that we are here to help you learn how to write your own code. We are not here to act as your unpaid programming staff.
# 3  
Old 02-05-2018
thanks so mutch , lots of questios.
Quote:
Originally Posted by Don Cragun
First let us start with the standard questions that should be answered in your first post in any technical thread:
  1. What operating system are you using?
  1. UBUNTU LTS 16.04
    Quote:
  2. What shell are you using?
bash
Quote:
  • What have you tried to solve this problem on your own?
  • no i dont know awk well
    Quote:
    Then we can move on to details specific to this thread:
    1. Numbers do not contain underscore characters. Why do you call 001_1_174 a number?
    1. sorry, they are not number but strings just contain numbers and underline_
      Quote:
    2. What criteria are to be used to decide if the first column in an input line is numeric?
    not numeric,strings just contain numbers and underline_
    Quote:
  • Is the criteria that the second field on a line is the string "j"?
  • no, second field contain [a-z] and ./`'`][
    Quote:
  • Can your numbers have leading plus or minus signs?
  • no just digits
    Quote:
  • Can your numbers have decimal points? If so, what is your decimal point character?
  • no, numbers just plus digits contain [0-9]
    Quote:
  • Can your numbers have thousands separators?
  • no
    Quote:
  • Can your numbers have a leading or trailing currency symbol?
  • just digits
    Quote:
  • Where is this table that you have?
  • out of a code
    Quote:
  • What is the format of this table?
  • text.
    Quote:
    If you want us to do your work for you, you can at least give us the details needed to figure out what must be done. Note that we are here to help you learn how to write your own code. We are not here to act as your unpaid programming staff.
    so glad to explain me. so thanks.Smilie this is not commercial code just my Thesis.

    how can learn AWK or some text editors?

    Last edited by alii; 02-05-2018 at 02:45 AM..
    alii
    View Public Profile for alii
    Find all posts by alii
    # 4  
    Old 02-05-2018
    Quote:
    Originally Posted by alii
    . . .
    this is not commercial code just my Thesis.
    Thanks for being that open. Usually students' home- and coursework questions need to be posted in the in this forum under special homework rules. A thesis in a non-IT field I think is a border line case. Did you consider awk to check for NF (number of fields) equals 4 (save $1 then) or less than 4 (add saved $1 to begin-of-line then)?


    Quote:
    how can learn AWK or some text editors?
    There's text books on awk, and / or the man page. Look into these fora and try to understand the problems and track the solutions proposed. Start creating your own solutions to simple up to more complex problems.
    RudiC
    View Public Profile for RudiC
    Find all posts by RudiC
    # 5  
    Old 02-05-2018
    Quote:
    A thesis in a non-IT field I think is a border line case.
    Smilie
    can't thesis about IT-field?Smilie
    alii
    View Public Profile for alii
    Find all posts by alii
    # 6  
    Old 02-05-2018
    If your thesis is in an IT related field, please post in the homework forum, filiing in the ENTIRE form. I presume you will correctly cite the source of any solutions you'll find in these fora.
    RudiC
    View Public Profile for RudiC
    Find all posts by RudiC
    # 7  
    Old 02-05-2018
    may help me or NOT?
    alii
    View Public Profile for alii
    Find all posts by alii
    Login or Register to Ask a Question

    Previous Thread | Next Thread

    10 More Discussions You Might Find Interesting

    1. Shell Programming and Scripting

    Awk,sed,shell copy ID in new lines

    Hi all i want table file in pattern like under ID(digits and underline) phonetic begin_byte(only plus number) end_byte(only plus number) but ID loose in next lines of my file my input file like this: input 001_1_174 474536 482492 mo 482492 504062 'er/ 504062 517352 ruze 517352... (1 Reply)
    Discussion started by: alii
    1 Replies

    2. Shell Programming and Scripting

    Read first column and count lines in second column using awk

    Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
    Discussion started by: Padavan
    5 Replies

    3. Shell Programming and Scripting

    awk to filter out lines containing unique values in a specified column

    Hi, I have multiple files that each contain four columns of strings: File1: Code: 123 abc gfh 273 456 ddff jfh 837 789 ghi u4u 395 File2: Code: 123 abc dd fu 456 def 457 nd 891 384 djh 783 I want to compare the strings in Column 1 of File 1 with each other file and Print in... (3 Replies)
    Discussion started by: owwow14
    3 Replies

    4. Shell Programming and Scripting

    awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

    Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
    Discussion started by: jacobs.smith
    3 Replies

    5. UNIX for Dummies Questions & Answers

    awk solution to duplicate lines based on column

    Hi experts, I have a tab-delimited file with one column containing values separated by a comma. I wish to duplicate the entire line for every value in that comma-delimited field. For example: $cat file 4444 4444 4444 4444 9990 2222,7777 6666 2222 ... (3 Replies)
    Discussion started by: torchij
    3 Replies

    6. Shell Programming and Scripting

    Find duplicates in column 1 and merge their lines (awk?)

    Hi, I have a file (sorted by sort) with 8 tab delimited columns. The first column contains duplicated fields and I need to merge all these identical lines. My input file: comp100002 aaa bbb ccc ddd eee fff ggg comp100003 aba aba aba aba aba aba aba comp100003 fff fff fff fff fff fff fff... (5 Replies)
    Discussion started by: falcox
    5 Replies

    7. Shell Programming and Scripting

    Awk to display lines that contain a period only in the first column

    I've been trying to figure this out for quite a bit... I'm trying to check the first column for a period and only display the line if it contains a period. Below is a sample of the data i'm working with. www.homestorest 7200 IN CNAME www.homestorest.fishing.net.shopit.net.... (6 Replies)
    Discussion started by: spartan22
    6 Replies

    8. Shell Programming and Scripting

    Copy respective path next to last column with awk

    Hi to all, I have the short print out sample of the DOS command "dir S/" as showed below. Directory of C:\Program Files\Winamp\Skins\Bento\window 02/12/2010 11:35 p.m. <DIR> . 02/12/2010 11:35 p.m. <DIR> .. 11/12/2009 10:31 a.m. 13,556... (3 Replies)
    Discussion started by: cgkmal
    3 Replies

    9. Shell Programming and Scripting

    awk/grep copy and paste and insert in between lines.

    Hi all, I'm a unix newb andI'm trying to write a script that can copy some text paste it in a certian place and then add a number. It's not really clear but I'll show an example. what the file looks like right now: Linux 2.6.24-24-generic (abc) 07/15/09 23:25:01 CPU ... (6 Replies)
    Discussion started by: the1hand3r
    6 Replies

    10. Shell Programming and Scripting

    How to copy multiple lines from a file to another using AWK?

    Hi, I have a abc.txt file. In this file there is a SQL query which Iwant to copy and print it on another file.The query (for eg) is written like this: SELECT field1, field2, field3 from table1,table2 where <conditions> END I want to copy this query to another... (3 Replies)
    Discussion started by: jisha
    3 Replies
    Login or Register to Ask a Question