1

I want to process PCAP file,then use WholeFileInputFormat. The input of the map is <filename,content>. How to get the content by using shell script?

6
  • 1
    The input of the map is <filename,content> Commented Dec 13, 2013 at 13:38
  • I don't understand the question. Please provide sample input and your desired output. Commented Dec 13, 2013 at 16:33
  • The input of the mapper is a file like "key \t this is the value,and I \n want to get the value. " . The output I want to get is the part of that file, like "this is the value,and I \n want to get the value.", how to use shell scripts to do it? Commented Dec 14, 2013 at 3:22
  • My question looks like this ,but the value is the content of a file,There are many lines of the file [Links]stackoverflow.com/questions/15365871/… Commented Dec 14, 2013 at 3:31
  • So, given a filename, return the contents minus a "word \t" on the first line? Commented Dec 14, 2013 at 20:14

1 Answer 1

0
# test file:
echo -e "foo bar\tthis is\nthe rest of the content" > file

contents=$( sed '1s/[^\t]*\t//' file )
label=$( sed '1{ s/\t.*//; q }' file )

You must quote the variables to preserve whitespace.

echo "$label"
echo "$contents"

You should always quote variables unless you know specifically why you shouldn't

Sign up to request clarification or add additional context in comments.

3 Comments

When I echo $contents,I get "this is the rest of the content".But I want to keep this contents in 2 rows,in other words,I wish to retain the '\n'.
Thank you for your patience to answer,thanks very much.
Contents is a hexadecimal file content,how to retain \x00?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.