Create a file on UNIX with multiple columns on certain condition
I need to write the list of files to a new file in one column , the second column would contain the first line of that file (header record extracted through head -1 ) and the third column would contain the last record of that file (trailer record tail -1 ) .
Example :- folder where the files exists : /tmp/multiple files List of files : file1 , file2 , file3 , file 4
Need to create a file xyz.hello at new folder /tmp/newfolder
file1 "header record of file1" "last line of file1"
file2 "header record of file2" "last line of file2"
file3 "header record of file3" "last line of file3"
file4 "header record of file4" "last line of file4
I am beginner to unix so I am having a hard time writing code , as of now I have just wrote down a sample to populate 2 colums , this too is not working .
Last edited by Don Cragun; 05-29-2014 at 10:04 PM..
Reason: Add CODE tags.
Thanks alot for replying , It is not what i want ..but it is a good head start...
I just want to head and tail the record of the first column (which are file name itself) of file "balancing" in the below code , not the balancing file itself .
For example , if the file contains 3 records as
abc
pqr
xyz
then I want to create a file with three colums like below like
abc <result of tail -1 abc > <result of head -1 abc>
pqr <result of tail -1 pqr> <result of head -1 pqr>
xyz <result of tail -1 xyz> <result of head -1 xyz>
The below code is giving me the result of balancing file first and last record only .
---------- Post updated at 08:21 PM ---------- Previous update was at 08:19 PM ----------
It is not a home work assignment , I need to create a file based on all the files that we are getting in our unix box each day, that shows the first and last record of each file based , so that we can validate the information in the same.
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. ---------- Post updated at 07:40 PM ---------- Previous update was at 07:26 PM ----------
To give it a chance to that code you need to change to the red highlight.
It needs to iterate through the same directory that you use in the find command. I was not trying to read from a file. I was trying to read the content of a directory.
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)
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)
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)
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)
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)
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)
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)
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)