Count characters in a csv file and add an word.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count characters in a csv file and add an word.
# 1  
Old 10-25-2012
Count characters in a csv file and add an word.

Hello,

I want to add a sentence to "post column" those who are only less than 30 characters.Thank you very much for your help.

Code:
"category","title","post" 
"Z","Zoo","test 54325 test 45363mc."
"Z","Zen","rs2w3rsj 2d342dg 2d3s4f23 d23423s23h 2s34s2423g ds232d34 2342."
"Z","Zet","test4444 dd."

output:

Code:
"category","title","post"
"Z","Zoo","test 54325 test 45363mc. Zoo is great"
"Z","Zen","rs2w3rsj 2d342dg 2d3s4f23 d23423s23h 2s34s2423g ds232d34 2342."
"Z","Zet","test4444 dd. Zet is great"

# 2  
Old 10-25-2012
And do you want to consider , also?

Not tested this. Hope it should work.Smilie

Code:
awk 'NR>1 && length($0)<30{sub("\"$","New settace \"",$0)}1' OFS="," file


Last edited by pamu; 10-25-2012 at 01:43 PM..
# 3  
Old 10-25-2012
Code:
awk  'BEGIN{OFS=FS="\",\""} NR>1 {if (length($3) < 30) sub("\"", " "$2" is great\"", $3)}1' file
"category","title","post" 
"Z","Zoo","test 54325 test 45363mc. Zoo is great"
"Z","Zen","rs2w3rsj 2d342dg 2d3s4f23 d23423s23h 2s34s2423g ds232d34 2342."
"Z","Zet","test4444 dd. Zet is great"

This User Gave Thanks to RudiC For This Post:
# 4  
Old 10-25-2012
This code works great Smilie Thank you very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Row Count in .csv file

Hi, I have to find the count of rows starting with "E," in given a.csv file . Sample Data File. E,2333AED,A,MC3,25,31-MAY-18 E,2333AED,A,MC3,25,31-MAY-18 CYMC3 25AED 0000 E,2333CZK,A,MC3,25,31-MAY-18 CYMC3 25CZK 0000 E,2333EUR,A,MC3,25,31-MAY-18... (3 Replies)
Discussion started by: Prabhakar Y
3 Replies

2. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

3. Shell Programming and Scripting

How to append word count at end of file?

Hi guys, I have to append the word count of a file at the end of the file name like this - > "filename_2345" where 2345 is the word count of "filename". How do i achieve this using one command ? I am not allowed to store the word count in a variable and then concatenate. Request your... (1 Reply)
Discussion started by: peter2312
1 Replies

4. Shell Programming and Scripting

Find word in file then get following characters

Hello, I have several xml files from which I want to find and return a particular string I want to locate the InId="00000008". Now that is inlcuded within a tag and ofcourse the number is different every time this is what I came up with given that after greping the line that contains the... (6 Replies)
Discussion started by: TasosARISFC
6 Replies

5. UNIX for Dummies Questions & Answers

find a word in a file, plus the next 6 characters?

I plan to use sed in a script to replace a string. My problem is the last 6 characters of the word to be replaced can be different each time, plus it's not always in the same spot on the line so I can't use cut or nawk to get the field. So I am looking for a way to find a certain word in a file,... (6 Replies)
Discussion started by: mikayla73
6 Replies

6. Shell Programming and Scripting

how to count a word in a file

dear all, i have a requirement to count the errors and display from a file. eg. file1.txt sjdgfjdgfgd ora-0001 sdjgfydh sdukgh7 23 sjdgfjdgfgd ora-0002 sdjgfydhsf34 ew 34v sjdgfjdgfgd ora-0008 sdjgfydh asdf asdfas sjdgfjdgfgd ora-0001 sdjgfydhjkbs ui873 sjdgfjdgfgd ora-0004 sdjgfydh... (9 Replies)
Discussion started by: unx100
9 Replies

7. Shell Programming and Scripting

how to count characters by line of file ?

Hello, Member or professional need help how to count characters by line of file Example of the file is here cdr20080817164322811681txt cdr20080817164322811txt cdr20080817164322811683txt cdr20080817164322811684txt I want to count the characters by line of file . The output that I... (4 Replies)
Discussion started by: ooilinlove
4 Replies

8. Shell Programming and Scripting

Record count of a csv file

Hello Gurus, We have a requirement to count the valid number of records in a comma delimited file with double quotes. The catch here is..few records have a new line carriage within the double quotes,,say for ex:we have a file called accounts the record count is 4827..but the actual valid count... (5 Replies)
Discussion started by: ajaykk
5 Replies

9. Shell Programming and Scripting

How to find a count of a word within a file

Hello, I'm looking for a wait to count the number of occurrences of a certain string of characters within a file. The file that I trying to parce has segments within the file that have a header and footer to each segment and I'm trying to do a count of the header string and compare it to a count... (9 Replies)
Discussion started by: bd_joy
9 Replies

10. UNIX for Dummies Questions & Answers

Word Count without any characters but the Output String

Hi all, I am logging any access to a server, and i wanted to write a script which tells me how much entries there are. The Problem is that "wc -l log" outputs the correct number of lines but with the name of the file attached. is there any nice possibility to solve this that i ONLY... (3 Replies)
Discussion started by: JP_II
3 Replies
Login or Register to Ask a Question