Replacing dynamically changing regular expressions using sed [closed] - shell

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
,"some values1","some values2",Not Processed,0,
Is there any way I could replace the above pattern, irrespective of whatever values come in some values1 or some values2 with the lines below,
,,,Not Processed,0,
This string is just a part of a large file I have.

This solves the problem I believe:
test_data() {
cat <<EOF
,"val1,val2...","val1,val2,val3..",Not Processed,0,
,"val1,val2..","",Not Processed,0,
,"","val1,val2,val3....",Not Processed,0,
EOF
}
test_data | sed -e 's/\(.*\),"[^"]*","[^"]*",\(Not Processed,0,\)\(.*\)/\1,,,\2\3/g'
Output:
▶ bash data.sh
,,,Not Processed,0,
,,,Not Processed,0,
,,,Not Processed,0,

Related

File name too long bash [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
i want to copy some files from ../soft to ../copu_new. The name of that tests are in ../sim/soft.txt.
I had en error : cp:cannot stat '../soft/file1.txt\file2.txt\file3.txt': File too long
Follow the code below:
input="../sim/soft.txt"
while read line
do
##to skip the first line of the file
a=$(tail -n +1)
##From string to table
for i in $a
do
table_soft[$i]="$i"
done
for i in "${tabke_soft[#]}"
do
cp ../soft/$i ../copy_new
done
done < $input
The file Soft.txt is :
###This all tests:
file1.txt
file2.txt
file3.txt
It's most likely the classic bash issue where trying to run an array through a for loop gives you all the content unless you wrap it in double quotes first. Try this..
a="$(tail -n +1)"

How to separate multiple parts of a line using ';' using shell script? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a '.GS3' file with multiple lines like this one:
0123456789 aaa.aaa3456
I want to separate it like this:
01234;56789 ;aaa.aaa;3456
I know the start and end of each part of the line. Is it possible to do this considering multiple lines? For example:
0123456789 aaa.aaa3456
aaaaabbbbbbbxxxxxxxwwww
Into
01234;56789 ;aaa.aaa;3456
aaaaa;bbbbbbb;xxxxxxx;wwww
.. but if it does have fixed lengths you can do it this way:
$ sed -r 's/^(.{5})(.{7})(.{7})(.{4})$/\1;\2;\3;\4/' test.txt
01234;56789 ;aaa.aaa;3456
aaaaa;bbbbbbb;xxxxxxx;wwww
I think .{5} is self explanatory. Due to the -r option the first group (.{5}) can be referenced by \1. It's a group due to ( and ).
The characters ^ and $ represent the beginning and ending of every line in the file test.txt.

How to remove leading / at each line a text file with sed Linux command [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
This is my text file and I want to remove every first line:
aaaa
bbbb/bbbb
/cccc/cccc
/Dddd/zzzz/wwww
.gggg
.oooo/sssss
/.vvvvv
!#%#/$%
How can I remove all first "/" from my text file?
I want the result text file to be like:
aaaa
bbbb/bbbb
cccc/cccc
Dddd/zzzz/wwww
.gggg
.oooo/sssss
.vvvvv
!#%#/$%
if it's any help, I'm using sed command.
sed can be instructed to replace the first / of each line with nothing:
sed 's_^/__' 'my text file name'

how to sed for certain parts of a string by delimiter [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have lots of different strings that look like redhat-ubi-ubi7-7.8
I want to use the string to make variables so that I end up having something like
vendor=redhat
product=ubi
image=ubi7
tag=7.8
How can I do this?
With bash and a here string:
string='redhat-ubi-ubi7-7.8'
IFS=- read -r vendor product image tag <<< "$string"
echo "$vendor"
Output:
redhat
Using P.E. parameter expansion.
string='redhat-ubi-ubi7-7.8'
vendor=${string%%-*}
tag=${string##*-}
image=${string%-*}
product=${image#*-}
product=${product%-*}
image=${image##*-}
printf '%s\n' vendor=$vendor product=$product image=$image tag=$tag
Output
vendor=redhat
product=ubi
image=ubi7
tag=7.8

Adding header to tsv file through terminal [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have many tsv files that are headerless, and would like to add the same header to each of them. How can I do this through the terminal or bash?
Thanks!
sed -i '1i \here comes header' files
files could be glob exp, like *.txt
Assume you have header in "head", tsv files as "body", how about cat head body | tee body

Resources