Create a file on UNIX with multiple columns on certain condition


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Create a file on UNIX with multiple columns on certain condition
# 8  
Old 05-29-2014
Quote:
Originally Posted by Aia
Sorry! I recognize I did not look hard enough to what you wanted and I based my answer on your first post.


Trying to reuse your code. I haven't test it.
Code:
#!/bin/bash

find /splunk/scrubbed/triumph/ -type f -mtime 1 > /tmp/try/balancing
list="/tmp/try/balancing"

while read file
do
    $first_line=$(head -1 ${file})
    $last_line=$(tail -1 ${file})
    printf "%s: \"%s\" \"%s\"\n" "${file}" "${first_line}" "${last_line}" >> temp_file.txt
done <  $list

#what's balancing1?
#temp_file.txt > balancing1

The dollar signs marked in red above won't work. And, there doesn't seem to be a need for either temp file. I think you're also looking for files modified during the last 24 hours; not files that were modified exactly 24 hours before you start find. Depending on file names and the contents of the 1st and last lines of the contents of those files, you also need some additional quotes. Try something like:
Code:
#!/bin/bash
find /splunk/scrubbed/triumph/ -type f -mtime -1 | while read file
do
    first_line="$(head -1 "$file")"
    last_line="$(tail -1 "$file")"
    printf '%s: "%s" "%s"\n' "$file" "$first_line" "$last_line"
done > balancing1

Note, however, that this hasn't been tested either.

Last edited by Don Cragun; 05-29-2014 at 10:55 PM.. Reason: Switch quotes to get rid of some escapes.
# 9  
Old 05-29-2014
awesome...your last post...solves the problem,.,..thanks alot to Don and Aia...you guys rock... :-)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split into multiple files by using Unique columns in a UNIX file

I have requirement to split below file (sample.csv) into multiple files by using the unique columns (first 3 are unique columns) sample.csv 123|22|56789|ABCDEF|12AB34|2019-07-10|2019-07-10|443.3400|1|1 123|12|5679|BCDEFG|34CD56|2019-07-10|2019-07-10|896.7200|1|2... (3 Replies)
Discussion started by: RVSP
3 Replies

2. UNIX for Beginners Questions & Answers

Need help search multiple condition from a file.

OS: window 7 shell : korn shell I have 2 file , i'm need grep data according File_1 from file 2. File_1 CAL_ENAB_N_4_ $2N12743_29 +12V File_2 NODE CAL_ENAB_N_4_ PINS 21548; PROBES P1465 3651, 46900 tn2700.1 LWT; WIRES (6 Replies)
Discussion started by: kttan
6 Replies

3. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns satisfy the condition

HI All, I'm embedding SQL query in Script which gives following output: Assignee Group Total ABC Group1 17 PQR Group2 5 PQR Group3 6 XYZ Group1 10 XYZ Group3 5 I have saved the above output in a file. How do i sum up the contents of this output so as to get following output: ... (4 Replies)
Discussion started by: Khushbu
4 Replies

4. Shell Programming and Scripting

Create a UNIX script file with multiple commands

Hi Good morning all, I want to create script file with multiple commands. For ex: pmrep connect is one of the command to connect to repository. pmrep objectexport is another command to export objects to a file. These commands should run sequentially.But when i try to execute this, the first... (4 Replies)
Discussion started by: SekhaReddy
4 Replies

5. Shell Programming and Scripting

Comparing Select Columns from two CSV files in UNIX and create a third file based on comparision

Hi , I want to compare first 3 columns of File A and File B and create a new file File C which will have all rows from File B and will include rows that are present in File A and not in File B based on First 3 column comparison. Thanks in advance for your help. File A A,B,C,45,46... (2 Replies)
Discussion started by: ady_koolz
2 Replies

6. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

7. Shell Programming and Scripting

Sort based on Multiple Columns in UNIX

Hi, I would like to sort a list in different ways: 1> Unique based on Field 1 with highest Field 4 For Instance Input: 1678923450;11112222333344;11-1x;2_File.xml 1678923450;11112222333344;11-1x;5_File.xml 1234567890;11113333222244;11-1x;3_File.xml Output: ... (7 Replies)
Discussion started by: DevendraG
7 Replies

8. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

9. Shell Programming and Scripting

create separate file after checking condition..

Problem : I want to create a separate file for country list if condition is true. Please help. ***************************************************** Input file: SV-INCR-139302-365540488-201104090934.sqllog SV-INCR-1082-552793184-201104040805.sqllog SV-INCR-1077-855045741-201104040805.sqllog... (4 Replies)
Discussion started by: humaemo
4 Replies

10. Shell Programming and Scripting

Compare columns of 2 files based on condition defined in a different file

I have a control file which tells me which are the fields in the files I need to compare and based on the values I need to print the exact value if key =Y and output is Y , or if output is Y/N then I need to print only Y if it matches or N if it does not match and if output =N , then skip the feild... (7 Replies)
Discussion started by: newtoawk
7 Replies
Login or Register to Ask a Question