How to count the field and add String?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to count the field and add String?
# 1  
Old 07-18-2016
How to count the field and add String?

Example i have 3 fields and i wanna add my input to the field after that (NF+1)

Code:
SID|Fname|Lname
123123:adds:asdasdasd

Result

Code:
SID|Fname|Lname|Number
123123:adds:asdasdasd:123123

---------- Post updated at 02:36 PM ---------- Previous update was at 02:23 PM ----------

Input is likes.

Code:
Enter your word you wanna add 
Number

Resuld

Code:
SID:Fname:Lname:Number

Moderator's Comments:
Mod Comment Please use CODE tags (not HTML tags) for sample input, sample output, and for code segments.

Last edited by Don Cragun; 07-18-2016 at 11:10 PM.. Reason: Change HTML tags to CODE tags.
# 2  
Old 07-18-2016
Quote:
Originally Posted by vutung1991
Example i have 3 fields and i wanna add my input to the field after that (NF+1)

Code:
SID|Fname|Lname
123123:adds:asdasdasd

Result

Code:
SID|Fname|Lname|Number
123123:adds:asdasdasd:123123

---------- Post updated at 02:36 PM ---------- Previous update was at 02:23 PM ----------

Input is likes.

Code:
Enter your word you wanna add 
Number

Resuld

Code:
SID:Fname:Lname:Number

Moderator's Comments:
Mod Comment Please use CODE tags (not HTML tags) for sample input, sample output, and for code segments.
What you are trying to do is not at all clear. Are you trying to add a string to the end of the heading line or are you trying to add numbers to the ends of other lines in your file?

Why do you care how many fields are in a line in your file if all you are doing is adding a string (or a number) to the end of every line in a file?

What operating system are you using?

What shell are you using?

What code have you written to try to do this on your own?

Is this a homework assignment?
# 3  
Old 07-19-2016
yes this is a part of my homework but i don't know how to solve it. I think i don't need to count the field and just add to the end of the head line. I'm using linux Mint terminal.
# 4  
Old 07-19-2016
Moderator's Comments:
Mod Comment Please refile in the Homework & Coursework forum with a completely filled out homework template.

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies

2. Shell Programming and Scripting

awk to skip header row and add string to field

The awk below does put in VUS in the 9th field but I can not seem to skip the header then add the VUS. I tried to incorporate NR >=2 and NR > 1 with no luck. Thank you :). input Chr Start End Ref Alt Func.refGene PopFreqMax CLINSIG Classification chr1 43395635 ... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Add specific string to last field of each line in perl based on value

I am trying to add a condition to the below perl that will capture the GTtag and place a specific string in the last field of each line. The problem is that the GT value used is not right after the tag rather it is a few fields away. The values should always be 0/1 or 1/2 and are in bold in the... (12 Replies)
Discussion started by: cmccabe
12 Replies

4. Shell Programming and Scripting

Grep a string and count following lines starting with another string

I have a large dataset with following structure; C 0001 Carbon D SAR001 methane D SAR002 ethane D SAR003 propane D SAR004 butane D SAR005 pentane C 0002 Hydrogen C 0003 Nitrogen C 0004 Oxygen D SAR011 ozone D SAR012 super oxide C 0005 Sulphur D SAR013... (3 Replies)
Discussion started by: Syeda Sumayya
3 Replies

5. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

6. Shell Programming and Scripting

Awk Search text string in field, not all in field.

Hello, I am using awk to match text in a tab separated field and am able to do so when matching the exact word. My problem is that I would like to match any sequence of text in the tab-separated field without having to match it all. Any help will be appreciated. Please see the code below. awk... (3 Replies)
Discussion started by: rocket_dog
3 Replies

7. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

8. Shell Programming and Scripting

Awk-Group count of field

Hi, Suppose if i am having a file with following records as given below. 5555 6756 5555 4555 4555 6767 how can i get the count of each record using AWK. Eg:5555 count should be 2 4555 count should be 2 6767 count should be 1 ... (5 Replies)
Discussion started by: tinivt
5 Replies

9. UNIX for Dummies Questions & Answers

Count of Field for Non-Empty

Hi Guys, I wanted to count the number of records for a particular field of a file. whose fields are separated by comma"," I fI use this command. cat "filename" cut -sd "," -f13 | wc -l This shows all the lines count including the blank values for the field number 13. I wanted to count... (2 Replies)
Discussion started by: Swapna173
2 Replies

10. UNIX for Dummies Questions & Answers

count the number of field in a string with deliminter

hi i am new to shell and would like ask some question about shell how am i suppose to count the number of fields with delementer example a:b:c:d would return me 4 how am i going to do it using shell?? what is the syntax for file locking? thanks a lot (9 Replies)
Discussion started by: yang
9 Replies
Login or Register to Ask a Question