awk copy first column in new lines

Hi all
i have table like this

input

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

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

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.

thanks so mutch , lots of questios.

  1. UBUNTU LTS 16.04
    [quote]
  2. What shell are you using?
    [/quote]
    bash
    [quote]
  3. What have you tried to solve this problem on your own?
    [/quote]
    no i dont know awk well
  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?
    [/quote]
    not numeric,strings just contain numbers and underline_
    [quote]
  3. Is the criteria that the second field on a line is the string "j"?
    [/quote]
    no, second field contain [a-z] and ./`'`][
    [quote]
  4. Can your numbers have leading plus or minus signs?
    [/quote]
    no just digits
    [quote]
  5. Can your numbers have decimal points? If so, what is your decimal point character?
    [/quote]
    no, numbers just plus digits contain [0-9]
    [quote]
  6. Can your numbers have thousands separators?
    [/quote]
    no
    [quote]
  7. Can your numbers have a leading or trailing currency symbol?
    [/quote]
    just digits
    [quote]
  8. Where is this table that you have?
    [/quote]
    out of a code
    [quote]
  9. What is the format of this table?
    [/quote]
    text.

so glad to explain me. so thanks.:b: this is not commercial code just my Thesis.

how can learn AWK or some text editors?

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)?

There's text books on awk , and / or the man page. Look into these forums and try to understand the problems and track the solutions proposed. Start creating your own solutions to simple up to more complex problems.

:smiley:
can't thesis about IT-field?:eek:

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 forums.

may help me or NOT?

IF your thesis is in an IT- related field, and IF the hint given in post#4 does not suffice, please repost in the homework forum.

Please write your answers as complete sentences.

In what field of study is your research?

What is the title of your thesis?

What degree are you seeking?

Who is your thesis advisor?

At what university are you studying?

Concering your answer to question VIII in post #3: If your table is in "out of a code", how is an awk script supposed to be able to read it? Are you saying that you have/will hard code the table into a BEGIN clause in your awk script?

Concerning your answer to question IX in post #3: If your table was in a file, the type "text" would say that there are no lines in the file containing more than LINE_MAX bytes (including the line-terminating <newline> characters, that the file contains no <NUL> bytes, and that if the file contains any characters at all the last character in the file is a <newline> character. That says nothing about how fields in your table are separated. It appears that you want the modified lines in your table to be written with the 1st field from the previous line whose first character is numeric followed by a single <space> character followed by the previous contents of that line of the table. Is that correct?

If you can't describe how this table exists, we have great difficulty in making any suggestions as to how to process the table. The art of programming is all about understanding the format and type of the input to be processed, the type and format of the output desired, and the rules that specify how the input needs to be transformed to produce the output.

One can learn a lot about awk (not AWK ; utility names on UNIX, Linux, and BSD systems are case sensitive), editors, and other utilities by reading their manual pages on your system. For example, you can see the manual page for awk by typing the command:
man awk
into your shell at a command prompt.

You can also look at hundreds (if not thousands) of threads in this forum that contain awk scripts to solve lots of different kinds of problems. Many of those scripts have comments that document what every line in the script is doing. For those that don't, if the thread is still open you can always and a post to a thread asking for an explanation of how that script works (or how particular lines in that script work). Use the advanced search feature in this forum for threads with tag "solved" and keyword "awk" for a list of 500 threads with examples.

One classic book describing awk is The AWK Programming Language published Jan 11, 1988 and written by the three authors of the utility Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan.

Thank you for giving me your time.:b:

Are these question important to answer my question? you know speech recognition. label speech signal in phone and word by byte of input signal.

you assume that table save in a directory!

i think you say true.
i confuse. explain again.
i have a table that first line have four columns.
column one begin with digits and contain digits and underline. column two contain alphabet not digits and columns three and four contain only digits.
in following it has three columns similar before except first column.(color string)
i want copy color string in new lines until next new line begin by another (color) string

input
001_1_174    [g/n                         474536         482492          
mo[g/n                    482492         504062          
'er/                      504062         517352          
ruze                      517352         529562                  
001_1_175    uz[`f                         960192         966656           
.ire                      966656         984416           
tuf/[                     984416         1006166    
001_1_174    [g/n                         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    uz[`f                         960192         966656           
001_1_175   .ire                      966656         984416           
001_1_175   tuf/[                     984416         1006166    



thanks:b:

I don't ask questions for the fun of asking questions. I was trying to get you to directly answer the questions needed to determine whether or not you are seeking a degree in information technology. Since you are unwilling to answer the questions of what university you're attending and who your thesis advisor is, we have to assume that you are asking us to do your homework for you and it is important for you to hide this information from us.

Homework and coursework questions can only be posted in the Homework & Coursework Questions forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulted in a forum infraction.

For the record, the last thing I would assume is that you stored your table in a file of type directory. I assumed that you would have stored your table in:

  • a single shell variable,
  • a single shell array variable (with each element of the array being a line n your table),
  • in three or four shell array variables (with each array being a column in your table),
  • a regular file (which would be a preferred choice),
  • a shared memory segment,
  • in a pipe (or named FIFO) written to by a process that is creating the data in your table (which would also be a preferred choice),
  • hardcoded into an awk , bc , dc , ed , ex , or sed script, or
  • any of several less common ways of storing data.

Your refusal to tell us how your table is stored and in what form you want the output to be produced makes it impossible for us to even guess at what tool should be used to process your data.

This thread is closed.

1 Like