Python Forum

Full Version: Syntax error: "(" unexpected
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey all. Im working on my python code where I intend to read a particular column from the text file and then print the duplicate entries in that file. My data is in the following format:
Output:
ARFCN: 1004, Freq: 931.0M, CID: 36231, LAC: 7713, MCC: 410, MNC: 4, Pwr: -35 ARFCN: 1008, Freq: 931.8M, CID: 47103, LAC: 7713, MCC: 410, MNC: 4, Pwr: -48 ARFCN: 6, Freq: 936.2M, CID: 10096, LAC: 10470, MCC: 410, MNC: 1, Pwr: -28 ARFCN: 10, Freq: 937.0M, CID: 30911, LAC: 10470, MCC: 410, MNC: 1, Pwr: -39 ARFCN: 10, Freq: 937.0M, CID: 30912, LAC: 10470, MCC: 410, MNC: 1, Pwr: -39 ARFCN: 49, Freq: 944.8M, CID: 15535, LAC: 52207, MCC: 410, MNC: 3, Pwr: -28 ARFCN: 50, Freq: 954.8M, CID: 15535, LAC: 52207, MCC: 410, MNC: 3, Pwr: -28 ARFCN: 66, Freq: 948.2M, CID: 10001, LAC: 470, MCC: 410, MNC: 6, Pwr: -39 ARFCN: 100, Freq: 955.0M, CID: 667, LAC: 1007, MCC: 410, MNC: 3, Pwr: -30
Now I intend to print line 4 and 5 because values of ARFCN are 10 in both cases. Similarly, I want to print 6 and 7 because the value of CID is same for both.

I began my coding by using the uniq command

uniq -d alpha.txt

However, this doesnt give the output as long as the entire entry is similar.

I then moved forward to first read a particular column of the text file and then use this entry on that:
#! /bin/sh
clear
echo "                      */\*/\*/\*/\*/\*/\*/\*/\*/\*/\*/\*/\* "
echo "                      D A T A B A S E  C O M P A R I S O N  "
echo "                      *\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/* "
echo UNIQUE BTS TOWERS ARE

f=open('alpha.txt', "r")
lines=f.readlines()
result=[]
for x in lines:
	result.append(x.split(' ')[1])
However, running thsi returns me an error:
Error:
*/\*/\*/\*/\*/\*/\*/\*/\*/\*/\*/\*/\* D A T A B A S E C O M P A R I S O N *\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/* UNIQUE BTS TOWERS ARE ./ARFCN.sh: 8: ./ARFCN.sh: Syntax error: "(" unexpected
I am using python 3.7.3 on ubuntu 18.04 LTS.
Even if this code starts working, it would output only the repetitive ARFCN or CID value and not the whole entry, where as I would require the entire list to be printed.
I do not think you will be able to mix bash and python that way.
(Jul-20-2020, 06:11 AM)menator01 Wrote: [ -> ]I do not think you will be able to mix bash and python that way.

okay so how do you suggest that I go about it?
Tutorials here on the forum is a good place to start.
(Jul-20-2020, 06:15 AM)menator01 Wrote: [ -> ]Tutorials here on the forum is a good place to start.

Thankyou.