Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Interpret a string with escape characters from stdin

if I have a file like:

hello \n world

how can I print the contents of the file with the escape sequences interpreted, so in the terminal you see:

hello 
 world

I've tried cat file | xargs -I{} echo {} but that prints hello n world

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

printf's %b format specifier expands escape sequences:

$ printf '%b\n' "$(cat file)"
hello
 world

To read from stdin an unadorned cat will do:

$ printf '%b\n' "$(cat)"
hello
 world
over 4 years ago · Santiago Trujillo Report

0

I think

echo 'hello\\nworld' | xargs -I {} printf "%b" "{}"

is what you're after. But that requires you to have some control over the text sent over the pipe since it requires double backslashes.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!