How to implement a simple command/code for multiple files?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to implement a simple command/code for multiple files?
# 1  
Old 04-05-2019
How to implement a simple command/code for multiple files?

I have been extracting a row, based on multiple key word from a xls/csv file, by using the following command. I have to implement the same for multiple xls/csv files, therefore please help me to do the same.

Code:
awk '
{ tbp=0
  if ($0 ~ keyword1 && k1 == 0) { tbp=1; k1++ }
  if ($0 ~ keyword2 && k2 == 0) { tbp=1; k2++ }
  if ($0 ~ keyword3 && k3 == 0) { tbp=1; k3++ }
  if (tbp == 1) { print }
  if ( k1+k2+k3 >=3 ) exit
 }' keyword1="avrbs2" keyword2="avrbs2" keyword3="xop" 119.csv

Thanks in advanceSmilie
# 2  
Old 04-05-2019
Code:
for file in /Dir/Dir1/*.csv
do
awk ' $0 ~ keyword1"|"keyword2"|"keyword3 && k++<3; k==3{exit} ' keyword1="avrbs2" keyword2="avrbs2" keyword3="xop"  $file
done

This User Gave Thanks to anbu23 For This Post:
# 3  
Old 04-05-2019
Why not

Code:
awk '... ' *.csv

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run simple single command on multiple Linux servers?

Hi All, How can i run a single command on multiple servers with or without giving credentials. I have a file(servers.txt) which has got list of servers and i want to run a command lsb_release -dr on all these servers and get output of those servers against each server. I tried below code... (9 Replies)
Discussion started by: darling
9 Replies

2. Shell Programming and Scripting

Simple awk command to compare two files and print first difference

Hello, I have two text files, each with a single column, file 1: 124152970 123899868 123476854 54258288 123117283 file 2: 124152970 123899868 54258288 123117283 122108330 (5 Replies)
Discussion started by: LMHmedchem
5 Replies

3. Programming

Implement ps command in C

Hello, could anybody explain how the ps command works? I know something about the proc file system. But I'm still not sure about how it exactly works. Like ps without any option will print out the current user's processes, but it never displays my web browsers such as firefox or my LibreOffice... (3 Replies)
Discussion started by: freedombird9
3 Replies

4. Homework & Coursework Questions

How to implement wc command using awk?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here in flwng code \n is not working 2. Relevant commands, code, scripts, algorithms: Files: a.txt This... (0 Replies)
Discussion started by: sidpatil
0 Replies

5. Shell Programming and Scripting

How to implement a command n times?

I need to run a command n (n >= 100) times and the command running may take about 30 seconds. Can anyone help me with the shell script to achieve this? Thanks in advance. (5 Replies)
Discussion started by: zwei2011
5 Replies

6. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

7. Shell Programming and Scripting

simple join for multiple files and produce 3 outputs

sh script file1 filea fileb filec ................filez. >>output1 & output2 &output3 file1 z10 1873 1920 z_number1_E59 z10 2042 2090 z_number2_E59 Z22 2476 2560 z_number3_E59 Z22 2838 2915 z_number4_E59 z1 1873 1920 z_number1_E60 z1 ... (9 Replies)
Discussion started by: stateperl
9 Replies

8. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

9. Shell Programming and Scripting

Need assistance with simple shell script to organize files. [Code attached]

I need some help with this shell script for class. All it does is organize your files. It works, but in the log file, it needs to show the new filepaths of the moved files. Heres my log of my output: Starting to organize... movie2.wmv --> movie3.mov --> movie1.mpg --> song1.mp3 --> ... (3 Replies)
Discussion started by: ryandamartini
3 Replies

10. Shell Programming and Scripting

Trying to implement 'more' command

Hi all, i'm quite new in the UNIX world. So maybe i'm going to ask simple questions but they are unsolvable for me... I'm trying to implement the 'more' function or kinda of that, for improving my knowledges. But I encountered some problems that i hope u will help me to solve. The code i... (0 Replies)
Discussion started by: Cellofan
0 Replies
Login or Register to Ask a Question