Sponsored Content
Top Forums Shell Programming and Scripting Seperated a Column from 'ESC' Character seperated file Post 303020426 by wisecracker on Thursday 19th of July 2018 08:31:24 AM
Old 07-19-2018
Quote:
Originally Posted by neha_suri06
Hi Experts

I have an escape seperated fields in the unix file. And in the below format file I need to extract the first column. Please help its urgent.

Code:
cat -v op.dat | head

24397028^[ABCD1234^[ABCD1234^[ ^[May 24 2011 12:10PM^[^[^[CSGBU
2439707^[ABCD1234^[ABCD1234^[ ^[Oct 25 2011  9:42AM^[^[^[CSGBU

I want to extract the file in below format ( with only first column )

Code:
24397028
2439707

OSX 10.13.5, default bash terminal.

Code:
Last login: Thu Jul 19 13:26:35 on ttys000
AMIGA:amiga~> echo '24397028^[ABCD1234^[ABCD1234^[ ^[May 24 2011 12:10PM^[^[^[CSGBU
> 2439707^[ABCD1234^[ABCD1234^[ ^[Oct 25 2011  9:42AM^[^[^[CSGBU' > /tmp/escape
AMIGA:amiga~> hexdump -C /tmp/escape
00000000  32 34 33 39 37 30 32 38  5e 5b 41 42 43 44 31 32  |24397028^[ABCD12|
00000010  33 34 5e 5b 41 42 43 44  31 32 33 34 5e 5b 20 5e  |34^[ABCD1234^[ ^|
00000020  5b 4d 61 79 20 32 34 20  32 30 31 31 20 31 32 3a  |[May 24 2011 12:|
00000030  31 30 50 4d 5e 5b 5e 5b  5e 5b 43 53 47 42 55 0a  |10PM^[^[^[CSGBU.|
00000040  32 34 33 39 37 30 37 5e  5b 41 42 43 44 31 32 33  |2439707^[ABCD123|
00000050  34 5e 5b 41 42 43 44 31  32 33 34 5e 5b 20 5e 5b  |4^[ABCD1234^[ ^[|
00000060  4f 63 74 20 32 35 20 32  30 31 31 20 20 39 3a 34  |Oct 25 2011  9:4|
00000070  32 41 4d 5e 5b 5e 5b 5e  5b 43 53 47 42 55 0a     |2AM^[^[^[CSGBU.|
0000007f
AMIGA:amiga~> _

There is no escape character, there are however a carat with a left hand square bracket representing an escape - so is it a real escape character [0x]1B you need to be detected or is the carat good enough?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search and then concat 4m other file (comma seperated)

My query is now a bit simplified. file1.txt names; ID; value1 ; values N; ABC; 1 ; a18 ; ... CDF; 2 ; b16 ; .. ABC; 1 ; c13 ; ...... EFG; 3 ;d12 ; ... file2.txt ID(Unique);smVals; smVal1; smVal N; 1; ...; ...; ...; 2; ..; ..; ..; 3; ..; ..; ..; ... (1 Reply)
Discussion started by: szchmaltz
1 Replies

2. UNIX for Dummies Questions & Answers

Problem with tab seperated file in UNIX

Hi All, I am facing a problem while getting the data from an Oracle table Problem: I am getting rows from an Oracle table to a tab seperated file. One of the columns in that table have value with in between spaces like AAAAA AAA It's loading fine to .tab file. But when... (2 Replies)
Discussion started by: pssandeep
2 Replies

3. Shell Programming and Scripting

Removing blank lines from comma seperated and space seperated file.

Hi, I want to remove empty/blank lines from comma seperated and space seperated files Thanks all for help (11 Replies)
Discussion started by: pinnacle
11 Replies

4. Shell Programming and Scripting

Trimming fields for comma or pipe seperated file

I have file like this FileA: abc , "helloworld" , america def,asia, japan ghi, africa, ipl Output Needed: abc,"helloworld",america def,asia,japan ghi,africa,ipl I would like to implement using awk. I want to trim each field for its leading and trailing spaces. (7 Replies)
Discussion started by: pinnacle
7 Replies

5. Shell Programming and Scripting

Convert comma seperated file to line seperated.

Hi, I have data like this. 1,2,3,4 Output required: 1 2 3 4 I am trying to use tr function but getting error. Help is appreciated. (6 Replies)
Discussion started by: pinnacle
6 Replies

6. UNIX for Advanced & Expert Users

grep 7th column from a file seperated with ^

Hi, Can anyone help: I want to get the 7th column of a file seperated by ^ Num:^ 1^ testdevice1^10.1.1.1^PT1X23^true^HD^175^up^false^bad Num:^ 2^ testdevice2^10.1.1.2^ST1X23^true^SN^175^up^false^bad Expected result: HD SN Appreciate your help. (2 Replies)
Discussion started by: sureshcisco
2 Replies

7. UNIX for Dummies Questions & Answers

Need help removing leading spaces from one field in comma seperated file

Using awk or sed, I'd like to remove leading spaces after a comma and before a right justified number in field 6. Sounds simple but I can't find a solution. Each field's formatting must stay intact. Input: 40,123456-02,160,05/24/2012,02/13/1977, 10699.15,0 Output:... (5 Replies)
Discussion started by: Scottie1954
5 Replies

8. Shell Programming and Scripting

Seperated by columns, merge in a file, sort them on common column

Hi All, I have 4 files in below format. I took them as an example. File 1: Cut from position 1-4 then 6-7 then 8-14 then rest left and make them as columns in one new file. Inserting character H to the initial of all line like HCTOT. CTOT 456787897 Low fever CTOR 556712345 High fever... (2 Replies)
Discussion started by: Mannu2525
2 Replies

9. Shell Programming and Scripting

SUM semicolon-seperated values from txt-file

Hello, (I'm a shell beginner) how can I sum the bold values of the following txt-file (values.txt) with bash shell. The result of the sum should be written in a new txt file (sum.txt): ... Thanks in advance (5 Replies)
Discussion started by: milu
5 Replies

10. Shell Programming and Scripting

Need Help in rearranging the content of a file comma seperated

I have a file with the below content a = test1 b = test2 a = test3 b= test4 c = test6 b = test5 d = test7 d = test9 Need the output to be as follows a = test1,test3 b = test2, test5 c = test6 d = test7, test9 (4 Replies)
Discussion started by: iron_michael86
4 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 09:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy