Make all lines divisible by three


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Make all lines divisible by three
# 1  
Old 08-13-2012
Make all lines divisible by three

Hi,

I need some help with the following: I need all lines in a file divisible by three, so for a file like this:

Code:
1
11
111

I want to add characters to make them all divisible by three (e.g. with an X):

Code:
1XX
11X
111

I would like to also ignore all lines that begin with the character >:

Code:
>header
1
11
111

becoming:

Code:
>header
1XX
11X
111

THANK YOU!!!!

Last edited by Scott; 08-13-2012 at 09:33 AM.. Reason: Code tags
# 2  
Old 08-13-2012
Try:
Code:
perl -ple 'if(!/^>/){$_.="X" x (3-length)}' file

# 3  
Old 08-13-2012
Code:
awk '!/^>/{while(length%3) $0=$0 "X";if(!length) $0="XXX"}1' infile

This User Gave Thanks to elixir_sinari For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add extra spaces to make all lines the same length?

Hello to all, I'm trying to format a file to have all lines with the same length (the length of the longest line) adding needed extra spaces at the end. Currently I have the awk script below that adds one space the end of each that have a lenght lower than 35, but I don't know how to add... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

2. Shell Programming and Scripting

Make multiple lines into single quoted comma separated Linux

Hi, I want to change a file file1.txt: 1234 3456 2345 6789 3456 2333 4444 As, file2.txt in Linux: '1234','3456','2345','6789','3456','2333','4444' Could someone please help me. (Single liner sed, awk will be welcome!) (7 Replies)
Discussion started by: wiweq05
7 Replies

3. Programming

Issue with make, no rule to make target etc.

I have been trying to split up my src directory to clear out files that are not re-compiled very often. Now I have the following setup in my trunk, trunk/bld trunk/src/ trunk/src/src_server trunk/makefile.linux In the make file, I have compile rules SOURCELOC = src # compile src c++... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

4. Shell Programming and Scripting

How to make duplicate lines

input tophr5:178975153-178982740:+ tophrX:14502176-14502376:+ output >tophr5:178975153-178982740:+ tophr5:178975153-178982740:+ >tophrX:14502176-14502376:+ tophrX:14502176-14502376:+ (2 Replies)
Discussion started by: quincyjones
2 Replies

5. UNIX for Dummies Questions & Answers

sed command, make multiple lines into one

:confused:Hi, I'm relativley new at unix so am having difficulties at the most basic of areas. I am trying using sed to make multiple lines into one line. For example, i would like: Mary had a little lamb to look like this Maryhadalittlelamb so far i have tried sed... (1 Reply)
Discussion started by: cavanac2
1 Replies

6. Solaris

Gani Network Driver Won't Install - make: Fatal error: Don't know how to make targ...

I attached a README file that I will refer to. I successfully completed everything in the README file until step 4. # pwd /gani/gani-2.4.4 # ls COPYING Makefile.macros gem.c Makefile Makefile.sparc_gcc gem.h Makefile.amd64_gcc ... (1 Reply)
Discussion started by: Bradj47
1 Replies

7. Shell Programming and Scripting

to make 2 lines into 1 line using awk

suppose i have a file AAAHHHHAHH AJJJJAAAAAA AJJJJJAAJJAK AJJAJJAJKKK the output suhd be AAAHHHHAHHAJJJJAAAAAAAJJJJJAAJJAKAJJAJJAJKKK (2 Replies)
Discussion started by: cdfd123
2 Replies

8. UNIX for Dummies Questions & Answers

How to make all lines into 1 line?

I have a file listing IP addresses, 1 per line, such as: 1.2.3.4 3.4.5.6 12.13.14.15 7.8.9.6 I want all of the entries to be on the same line, and quoted, such as: "1.2.3.4" "3.4.5.6" "12.13.14.15" "7.8.9.6" I got the quotes on there in vi with ":%s/^/"/g" and "%s/$/"/g" ... is there... (8 Replies)
Discussion started by: earnstaf
8 Replies

9. Shell Programming and Scripting

extract perticular lines and make them into speadsheet

Hi Masters, I knew this isn't a new issue, but couldn't find any similar threads. So, I have to bother you. Here is my input file (genomic data). The file has many sessions, each session seperated by //. Within eash session there is only one ID and GN line. ID 3HAO_HUMAN STANDARD; ... (4 Replies)
Discussion started by: mskcc
4 Replies

10. Shell Programming and Scripting

Make sed ignore lines

Hi I use sed in a script for severall changes in files. I whish one of the substitutions I made to be aplied to every line that has the word "scripts" with the exception for the ones that start with "rsh", wich I wish sed to ignore . Is this possible? If yes, how can I do it? The substitution... (2 Replies)
Discussion started by: Scarlos
2 Replies
Login or Register to Ask a Question