Remove first 2 characters and last two characters of each line
here's what im trying to do.
i have a file containing lines similar to this:
data.txt:
I need to remove the first two characters and the last two characters of each line. but i also need to be able to put those removed characters back to where they were before they were removed.
so, here's what i'm doing so far:
This only removes the first two characters of each line and the last two.
where im getting stuck is, how do i get back the removed characters?
a thought that crossed my mind is to first get the first two characters of each line line. save it to a file and do the same for the last two characters.
then find a way to merge firstwo.characters and lastwo.characters with data.txt.pruned so they look like the original text in data.txt?
i suppose the commands join may be used here. but im looking for something that can work on all Unix systems (portable), especially those systems that are considered "embedded". if awk can be used here, that'll be great.
Could you please try following and let me know how it goes then, though I am not sure about your complete requirement.
So when we are running the script then following will be the output.
This is just an example where you could use the first 2 characters, last 2 characters and rest of the line without them in a script itself rather than saving them into files. If you have more requirements then kindly do let us know on same.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
My suspicion is that this is a private security key and you want to be able to email it safely. My concern is that you will also transmit the way that the key is reconstituted and thereby expose how to reconstitute your private key to anyone snooping your traffic.
There are various ways that this can be done as shown already, and more besides, but I just wanted to check that we are not encouraging you to follow an insecure design.
Please feel free to tell me I'm wrong - I'd be relieved.
I have a test file with the following format, It contains the username_date when the user was locked from the database.
$ cat lockedusers.txt
TEST1_21062016
TEST2_02122015
TEST3_01032016
TEST4_01042016
I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
I want to remove 1st and last two characters of each line of the file
Ex: file1
zzfile1ee
@xfile2:y
qfile3>>
@ file4yy
and redirect to the file called new
Basically file will have any charcter including space, spical character...
Please help.... (7 Replies)
I have a the following line
22.152.25.36 - K##### "GET /DGGKE/GetMail.do;jwebsphere=FADFFFGSFGSFGSDGFSDFGSDFGSDF HTTP/1.1" 200 44948
Need a cut command which should give me the below output
22.152.25.36 - K##### "GET /DGGKE/GetMail.do HTTP/1.1" 200 44948
Note: The value of jwebsphere can... (6 Replies)
Hi,
I have a file with lines like below.
I need to remove first few characters from each line until a date format is found.
05/06/12 20:47:02 GUMGUY@98.192.174.74{42B42A72AC955F5926621273E3A15059.tomcat2}TP-Processor15 LogExchUsage: ERROR:
05/06/12 20:47:02... (8 Replies)
I tried using below command
tr -cd "" < InputFile.xml > output.txt ============= This removes all the tabs/newline/extra spaces from a file
it successfully removed all the extra spaces,tabs and new line characters but then the complete file become one record. I want to retain one new line... (1 Reply)
Hi,
I have a file with ';' delimeter which has some new line characters. How can I delete the new line characters if they are found between 1 to 10 fields.
Thanks (3 Replies)
Hello,
Is there a simpler way to remove special characters (color codes) from each lines in a log file?
I use sed like in the example below but I think there should be a more simple way to achieve the same result:
$ cat -vet file1
^, , , ,
Maybe to convert the file somehow?
... (5 Replies)
Hello,
I have multiple lines in a file, each of which will have data that looks like this:
xxxxxyyyyzzzz4abcdXYZXYZXYZ
pqrstPQRST2cdPQRSTPQRST
lmnopqr6abcdefgRST.3abc
I want to be able to remove the number 4 + the following 4 characters (abcd) in the first line.
For the second line,... (1 Reply)
I am using awk and it stops when it encounter line greater then 3000 character. Is there any command which will help me remove line greater then 3000 characters. (10 Replies)