Sponsored Content
Top Forums Shell Programming and Scripting Need to prepare a CSV table with inputs from multiple files Post 303040662 by prvnrk on Sunday 3rd of November 2019 02:02:39 PM
Old 11-03-2019
@Neo - Thanks, Always I tried and shared my attempts here (if you look at my previous posts) but this time also I tried and gave it up after 80% completion. Now I completed my script which I don't like (as always) as it's messy. This does my job but not perfect.

@RudiC - Thanks I missed BitRate field. now I fixed.

Please see my Script and other files, Appreciate a Better version. Thannks!!

Code:
$ cat Final_Format.sh
#!/usr/bin/bash
cd /home/admin/HEVC1
echo "Sl#,VideoName,BitRate,`cat Required_para.txt | paste -sd "," -`" >/home/admin/HEVC1/MedInfo_Output.csv
countt=0
for VidX in Vid*
do
        countt=`expr $countt + 1`
        echo "${countt}" >/tmp/Req_Values_Vertical.txt
        echo "${VidX}" >>/tmp/Req_Values_Vertical.txt
        VidBitRate=`grep "HEVC " ${VidX} |grep Video |awk -F"/" '{print $3}' |sed 's/[^0-9]*//g'`
        echo "${VidBitRate}" >>/tmp/Req_Values_Vertical.txt

        grep "Encoding settings" ${VidX} |sed 's/\//\n/g' >/tmp/All_Values.txt
        grep "Encoding settings" ${VidX} |sed 's/\//\n/g' |grep = >/tmp/All_Values2.txt

                for param in `cat Required_para.txt` ; do
                grep "${param}"= /tmp/All_Values2.txt|head -1 >>/tmp/Req_Values_Vertical.txt
                done

        sed -i.bak 's/ //g' /tmp/Req_Values_Vertical.txt

        if [ `grep no-strong-intra-smoothing ${VidX} |wc -l` -gt 0 ]; then
        sed -i.bakk '/^aq-mode=.*/a strong-intra-smoothing=0' /tmp/Req_Values_Vertical.txt
        else
        sed -i.bakk '/^aq-mode=.*/a strong-intra-smoothing=1' /tmp/Req_Values_Vertical.txt
        fi
		
		if [ `grep selective-sao ${VidX} |wc -l` -eq 0 ]; then
        sed -i.bakkk '/^colorprim=.*/a selective-sao=NA' /tmp/Req_Values_Vertical.txt
        fi

        awk -F"=" '{print $NF}' /tmp/Req_Values_Vertical.txt >/tmp/Req_ValuesOnly_Vertical.txt
        cat /tmp/Req_ValuesOnly_Vertical.txt | paste -sd "," - >/tmp/Req_ValuesOnly_Horizontal.txt
        cat /tmp/Req_ValuesOnly_Horizontal.txt >>/home/admin/HEVC1/MedInfo_Output.csv
done

Code:
$ pwd
/home/admin/HEVC1
$ ./Final_Format.sh
$ cat MedInfo_Output.csv
Sl#,VideoName,BitRate,input-res,crf,aq-mode,strong-intra-smoothing,bframes,rc-lookahead,me,subme,merange,deblock,psy-rd,psy-rdoq,ctu,rdoq-level,max-merge,ref,max-tu-size,transfer,colormatrix,colorprim,selective-sao
1,Vid1,5750,1920x816,23.3,3,0,8,100,3,7,92,0:0,2.00,1.00,32,2,4,5,16,1,1,1,NA
2,Vid2,3711,1920x804,18.0,3,1,8,25,3,3,57,0:0,2.00,1.00,64,2,3,4,32,2,2,2,0
3,Vid3,7903,1920x800,18.0,3,1,8,25,3,3,57,0:0,2.00,1.00,64,2,3,4,32,2,2,2,0
$

$
Code:
$ cat Required_para.txt
input-res
crf
aq-mode
strong-intra-smoothing
bframes
rc-lookahead
me
subme
merange
deblock
psy-rd
psy-rdoq
ctu
rdoq-level
max-merge
ref
max-tu-size
transfer
colormatrix
colorprim
selective-sao


Last edited by prvnrk; 11-03-2019 at 04:14 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Pull out multiple files from DB table and redirect all those files to a differetn directory?

Hi everyone!! I have a database table, which has file_name as one of its fields. Example: File_ID File_Name Directory Size 0001 UNO_1232 /apps/opt 234 0002 UNO_1234 /apps/opt 788 0003 UNO_1235 /apps/opt 897 0004 UNO_1236 /apps/opt 568 I have to... (3 Replies)
Discussion started by: ss3944
3 Replies

2. Shell Programming and Scripting

Copying multiple csv files

Hi, I have mutiple csv files at server1 at /apps/test/data. I needed a script that would copy these csv files from server1 at /usr/data, put them in server2,archive the earlier files that were present in server2 before removing those already present. Kindly help. (2 Replies)
Discussion started by: Alok Ranjan
2 Replies

3. Shell Programming and Scripting

Field validations in multiple files CSV

Hi, I am regular reader of this forum. My advanced thanks to everyone. Below given are the sample files INDATA (Main data) Fild1Çfld2Çfld3….. Fild1Çfld2Çfld3….. Fild1Çfld2Çfld3….. Fild1Çfld2Çfld3….. Fild1Çfld2Çfld3….. . . N records (140000) eg GRPDATA (Reference file) (2 Replies)
Discussion started by: hyperion.krish
2 Replies

4. Shell Programming and Scripting

reading information from a table and apply a command on multiple files

Hey gyuz, I wanna calculate the number of mapped reads of a bam file in a region of interest. I used this code to do so : samtools view input.bam chrname:region1 > region1.txt This will store all the reads from given bam file within the region of interest in region1.txt Now I have... (5 Replies)
Discussion started by: @man
5 Replies

5. Shell Programming and Scripting

Find values in multiple csv files

Hi, I'd like to find the values of certain fields in multiple csv files stored in 1 directory based upon an input search string. An fgrep returns the complete record, I only want certain fields. Thanks in advance for your help. Perry (6 Replies)
Discussion started by: biscayne
6 Replies

6. Shell Programming and Scripting

Split a .csv File into Multiple Files

Hi guys, I have a requirement where i need to split a .csv file into multiple files. Say for example i have data.csv file and i have splitted that into multiple files based on some conditions i.e first file should have 100, last file 50 and other files 1000 each. Am passing the values in... (2 Replies)
Discussion started by: azherkn3
2 Replies

7. Shell Programming and Scripting

Insterting column in csv from multiple files

Hello, I have a spec file that contains a lot of strings that looks like this: PC DELL OptiPlex 3010MT i3 3220/2GB/500GB/DVD-RW/FREE DOS / 5Y NBD Intel i3 3220 (Dual Core, 3.30GHz, 3MB, w/ HD2500 Graphics), 2GB (1x2GB) DDR3 PC3-1600MHz, 500GB HDD SATA III 7200rpm, DVD+/-RW (16x),... (9 Replies)
Discussion started by: g9100
9 Replies

8. UNIX for Dummies Questions & Answers

Load multiple files into a table

Hi, I need to load data from two files to a single table. My requirement is that I get two files in which a few column data are manadatory. These files are identified based on the file name. For example, I have two files ABCFile and BCDFile. ABCFile has mandatory data in column 3 and 4... (0 Replies)
Discussion started by: reshma15193
0 Replies

9. Shell Programming and Scripting

CSV joining and checking multiple files

Hello, For our work we use several scripts to gather/combine data for use in our webshop. Untill now we did not had any problems but since a couple days we noticed some mismatches between imports. It happened that several barcodes where matched even though it was a complete other product. Of... (19 Replies)
Discussion started by: SDohmen
19 Replies

10. UNIX for Beginners Questions & Answers

Export Oracle multiple tables to multiple csv files using UNIX shell scripting

Hello All, just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table. Can you please suggest why? or any better idea? export FILE="/abc/autom/file/geo_JOB.csv" Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Discussion started by: Hope
16 Replies
PTS_SOURCE(1)						       AFS Command Reference						     PTS_SOURCE(1)

NAME
pts_source - Read pts commands from a file SYNOPSIS
pts source [-file] <file name> [-cell] <cell name> [-noauth] [-localauth] [-force] pts so [-f] <file name> [-c] <cell name> [-n] [-l] [-f] DESCRIPTION
The pts source runs commands from a file as if they were typed in pts interactive mode. The command can be run from the command line or interactively. CAUTIONS
Prior to OpenAFS 1.4.5 and OpenAFS 1.5.23, the pts source command was only available on Unix or Linux and when OpenAFS was compiled with the supergroups option (disabled by default). As of OpenAFS 1.4.5 and 1.5.23, it is always available. OPTIONS
pts source takes the following options: -cell <cell name> Names the cell in which to run the command. For more details, see pts(1). -force Enables the command to continue executing as far as possible when errors or other problems occur, rather than halting execution at the first error. -help Prints the online help for this command. All other valid options are ignored. -localauth Constructs a server ticket using a key from the local /etc/openafs/server/KeyFile file. Do not combine this flag with the -cell or -noauth options. For more details, see pts(1). -noauth Assigns the unprivileged identity anonymous to the issuer. For more details, see pts(1). OUTPUT
This command shows the output of each command in the file as if it were run normally. EXAMPLES
Here is an example of using pts source in a pts interactive session: % echo examine admin > /tmp/commands.txt % pts interactive pts> source /tmp/commands.txt Name: admin, id: 1, owner: system:administrators, creator: anonymous, membership: 2, flags: S----, group quota: 20. pts> quit % SEE ALSO
pts(1), pts_interactive(1), pts_quit(1), pts_sleep(1) COPYRIGHT
Copyright 2007 Jason Edgecombe <jason@rampaginggeek.com> This documentation is covered by the BSD License as written in the doc/LICENSE file. This man page was written by Jason Edgecombe for OpenAFS. OpenAFS 2014-04-08 PTS_SOURCE(1)
All times are GMT -4. The time now is 09:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy