Convert tick to new lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert tick to new lines
# 1  
Old 10-01-2016
Convert tick to new lines

i can convert ticks to new lines using something like this:

Code:
tr '`' '\n' < filename
or
tr "\`" "\n" < filename

or vice versa

Code:
tr '\n' '`' < filename
or
tr "\n" "\`" < filename

however, this command seems to not work the same on every system. it works on ubuntu, and it works on redhat when run from the command line. but if run from a script, it gets rid of the '\n' and turns it to 'n', which then ends up replacing all letter "n's with '`'.

is there a different command i can use for this that will behave the same on every unix system? i've spent a couple of hours on this and nothing seems to work.

i just want to be able to translate all new lines to ticks and also be able to translate back to new lines in a reliable way.
# 2  
Old 10-01-2016
Hello SkySmart,

If you want to use an awksolution then following may help you in same. Let's say our Input_file is as follows for an example.
Code:
cat Input_file
singh_is`_king1233
``is the input_file here.
test test test
test ` newline test `` again new line test

Now following is the command for your requirement.
Code:
awk -vs1="\`" '{gsub(s1,"\n",$0)} 1'  Input_file

Output will be as follows.
Code:
singh_is
_king1233


is the input_file here.
test test test
test 
 newline test 

 again new line test

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-01-2016
You could try perl as an alternative:
Code:
perl -pe 'y/`/\n/' file 
perl -pe 'y/\n/`/' file

But tr should work. How do you run it from a script and on what OS. Can you give an example?

Last edited by Scrutinizer; 10-01-2016 at 02:12 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 10-01-2016
Hello SkySmart,

I am not sure about all O.S(or on which you are currently), I had tested this following in Ubuntu and BASH and it worked fine for me. Could you please try following and let me know if this helps you. So let's say we have following Input_file.
Code:
cat  Input_file
singh_is`_king1233
``is the input_file here.
test test test
test ` newline test `` again new line test

Code:
tr "$(printf "\x60\n")" "\n" <  Input_file

Output will be as follows.
Code:
singh_is
_king1233


is the input_file here.
test test test
test 
 newline test 

 again new line test

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 10-01-2016
Scrutinizer is right: tr works in both directions, on command line or in script, in Ubuntu or in FreeBSD. RedHat, being another linux flavour, shouldn't make any problems.
So - give us more info about the case when is doesn't work. How is the script run? What environment does it have? Any error messages?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Ardunio Tick-Tock DS1307 RTC Shield Basics

This arrived in the mail from China a few days ago and, for the small money, has been a lot of fun. Clock Shield RTC module DS1307 module Multifunction Expansion Board with 4 Digit Display Light Sensor and Thermistor For Arduino This board is a lot of fun for a few bucks. It has a low... (1 Reply)
Discussion started by: Neo
1 Replies

2. UNIX for Beginners Questions & Answers

Convert a horizontal lines to vertical lines in a csv file

Hi.. I need some help in converting the below horizontal lines to vertical lines format. can anyone help me on this. input file Hour,1,2,3,4,5 90RT,106,111,111,112,111 output file Hour,90RT 1,106 2,111 3,111 4,112 5,111 (3 Replies)
Discussion started by: Raghuram717
3 Replies

3. UNIX for Dummies Questions & Answers

Awk: convert rows to columns every n lines

Hi guys! I use AWK commands under GAMS to predispose the data files to be read by GAMS. I have a file which contains groups of data I need. Unfortunately I have the data spread in 3 rows for each subject. Here's an example (the file is really long) 1 0 2.0956 100.00 250.00 100.00 2.0956... (4 Replies)
Discussion started by: Pintug
4 Replies

4. Windows & DOS: Issues & Discussions

Clock doesn't tick

This is a strange one, I've never seen anything like it; the realtime clock doesn't tick while the computer's idle, only when you're watching it. Leave for 3 hours and it'll be 3 hours off. It still advances when it's off however, or the time would be far more incorrect than it is. About all... (10 Replies)
Discussion started by: Corona688
10 Replies

5. Shell Programming and Scripting

awk or sed - Convert 2 lines to 1 line

Hi, Just trying to get to grips with sed and awk for some reporting for work and I need some assistance: I have a file that lists policy names on the first line and then on the second line whether the policy is active or not. Policy Name: Policy1 Active: yes Policy... (8 Replies)
Discussion started by: guinch
8 Replies

6. Ubuntu

Cannot see 'tick boxes' and other contents when installed programmes using Wine. Is there any other

Hi! I have installed ubuntu out of an error, a bit of frustration, a bit of annoyance and a bit of excitement! I am (was!) a windows user. I had windows 7 on my laptop. You might already know how famous windows is with nasty viruses. I got one too! Had no option but to get rid of the whole... (3 Replies)
Discussion started by: ubuntu_noob
3 Replies

7. Shell Programming and Scripting

How to convert three blank lines to one

Hi Guys, I have a file as follows: uuy uuy urrt rrte rtrtrt trtrtr jhf jhf jhfj (3 Replies)
Discussion started by: npatwardhan
3 Replies

8. Shell Programming and Scripting

convert a file from lines to columns in perl

Hi all, I want to convert a file from lines to columns in perl for example "abcd" convertd to a b c d pleas help me :( (3 Replies)
Discussion started by: bioinf
3 Replies

9. Linux

kernel:how to modify and read the tick rate:HZ

hi, one of our customer is facing an issue with jiffies wrap up. on a 32 bit machine, the variable jiffies count upto 472 days. the customer's server was up for 472 days ('uptime') and to reproduce the same, i tried to change the variable HZ in linux-2.6..23.9/include/asm-i386/param.h from... (0 Replies)
Discussion started by: amit4g
0 Replies
Login or Register to Ask a Question