How to copy lines from a csv file that contain "D,1", "D,2", or "D,3" into a txt file where the solutions are in the same order as the csv file - linux

How can I copy lines from a .csv file that contain "D,1", "D,2", or "D,3" into a .txt file where the solutions are in the same order as the .csv file? Would I consider using grep? I'm new to the Linux command line and have only used sed and head so far.

Related

How to extract each line from a file, into separate files in Linux Shell Script

How to extract each line from a file, into separate files in Linux
Example :
If the file content 10 rows, it will be 10 files.
if File contents
12345
1uthste
128766
First-line should move to 1.txt
Second-line should move to 2.txt
like this goes on.

Adapt command to creating csv file from storage content including date(time) & file size also

According to thread:
Linux: fast creating of formatted output file (csv) from find command
there is a suggested bash command, including awk (which I don't understand):
find /mnt/sda2/ | awk 'BEGIN{FS=OFS="/"}!/.cache/ {$2=$3=""; new=sprintf("%s",$0);gsub(/^\/\/\//,"",new); printf "05;%s;/%s\n",$NF,new }' > $p1"Seagate-4TB-S2-BTRFS-1TB-Dateien-Verzeichnisse.csv"
With this command, I am able to create a csv file containing "05;file name;full path and file name" of the directory and file content of my device mounted on /mnt/sda2. Thanks again to -> tink
How must I adapt the above command to receive date(&time) and file size also?
Thank you in advance,
-Linuxfluesterer

Batch script to change many .xlsx files to .csv

I have a folder with many subfolders (1000+) and inside the subfolders are a few excel files, in .xlsx format. I want to run a batch script from the main folder, which goes into each sub folder and changes each .xlsx Excel file into a .csv Excel file.
The formatting of the file system:
MainFolder
---subfolder1
----->file1.xlsx
---subfolder2
----->file2.xlsx
etc.
From this thread: Convert XLS to CSV on command line, I figured out that I can't just rename each .xlsx to .csv, so I made the ExceltoCSV.vbs file (the modified ScottF answer, second one down). My understanding is that I can make a for loop in a batch file to run ExceltoCSV.vbs for each sub folder. The following line of code is something i attempted, but it didn't work. It usually says *.xlsx file is not found.
for /R %%F in ("C:\MainFolder") do cscript ExceltoCSV.vbs *.xlsx *.csv
Also tried this:
for /d /r "C:\MainFolder" %%F in (.) do cscript ExceltoCSV.vbs "%%F\*.xlsx" *.csv
Error message:
C:\MainFolder\ExceltoCSV.vbs(17,1) Microsoft Excel: 'C:\MainFolder\folder1\*.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct.
The VBS script you got from SO only takes a string as an input. What you'll need to do is create a loop with a regex pattern that builds those file names dynamically and then run the script with an input string representing each file name. Pseudo code:
for loop (iterate over file names in dir){
set $file_name=$iterated_file_name_from_loop
ExceltoCSV.vbs "$file_name.xlsx" *.csv
}

Appending the text of a file

I am using Shell scripting. I tried the below option.
I want to append the part of a file to another part of a file.
I tried this command to append the content of a file.
Command:
/bin/cat ../../../test_op.txt/sql/part_code.txt >> ../../../PartitioningUtility/log/test_op.txt
To append the text of part_code.txt to test_op.txt.
No errors but the text is not appending.
Any Solution to this problem.
Any other option to append the data of a one file to another
If you want to append all content from '/bin/cat ../../../test_op.txt/sql/part_code.txt' to '../../../PartitioningUtility/log/test_op.txt' you could add 'cat' in the beginning:
cat ../../../test_op.txt/sql/part_code.txt >> ../../../PartitioningUtility/log/test_op.txt
That is assuming that file paths are correct.

Shell script handle string with sed

I have a text file, each line is one or more file paths separated with space, all the file has suffix dl, e.g.
/some/path/file.dl
/some/other/path/file2.dl /some/other/path2/file3.dl
/some/other/path3/file4.dl /some/other/path4/file5.dl ...
...
Now I need to transform the above file to another text file. Only the first file of every line should be changed to /out/P{fileName}.h:, {fileName} is the original file name without directory and suffix. e.g.
/out/Pfile.h:
/out/Pfile2.h: /some/other/path2/file3.dl
/out/Pfile4.h: /some/other/path2/file5.dl ...
...
So how can I write the linux shell script?
Try this command:
$ sed -r 's#^\S*/(\S*)\.dl#/out/P\1.h:#' input
/out/Pfile.h:
/out/Pfile2.h: /some/other/path2/file3.dl
/out/Pfile4.h: /some/other/path4/file5.dl

Resources