Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to get an if statement to work in bash that deals with lines beginning with in a text file.

Something like this:

shasum -a 256 file_A\\//.txt >> file_B.txt
if line begins with '' in file_B.txt
    then sed 's/^/^.{65}  /; s/$/$/' that line in file_C.txt
else
    if line not begin with '' in file_B.txt
        then sed 's/^/^.{64}  /; s/$/$/' that line in file_C.txt
    fi
fi

Contents of file_B.txt:

e5fba57b49dbe8196ee4fb4ddb407885582f88d8e52dfa6e5adb55204b589a88  /Users/1337/file_D.txt
66590f18dafff57160770d885b090d54455e0fc900342d7752dc420405ae50f5  /Users/1337/file_A\\::.txt

Contents of file_C.txt:

/Users/1337/file_D.txt
/Users/1337/file_A\::.txt

So, basically, the end result would look like this (this is inside file_C.txt):

^.{64}  /Users/1337/file_D.txt$
^.{65}  /Users/1337/file_A\::.txt$

because line 2 began with a and line 1 didn't.

If any of this is confusing, please don't hesitate asking me to clarify.

Mac OS X Yosemite, bash 3.2.57(1)-release

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
227 views
Welcome To Ask or Share your Answers For Others

1 Answer

Something like this?

while read -r line; do
    n=64; [ ${line:0:1} == \ ] && n=65
    echo "^.{$n}  ${line#*  }$"
done <file_B.txt >file_C.txt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...